Skip to content

Commit

Permalink
Release 1.22.0 rc2 (sora-xor#1187)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefashkaa authored Oct 2, 2023
1 parent 28b1d90 commit ddb0b77
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 62 deletions.
13 changes: 6 additions & 7 deletions public/marketing.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
[
{
"title": "JOIN AIRDROP",
"img": "/marketing/synths.png",
"backgroundColor": "var(--s-color-theme-accent)",
"link": "https://gleam.io/zHQmD/polkaswap-34000-xst-airdrop-campaign"
},
{
"title": "GET SORA CARD",
"img": "/marketing/card.png",
"backgroundColor": "#F8087B",
"backgroundColor": "var(--s-color-theme-accent)",
"link": "/#/card"
},
{
"title": "CONNECT WITH GOOGLE",
"backgroundColor": "var(--s-color-theme-accent)",
"link": "https://medium.com/polkaswap/how-to-use-connect-with-google-on-polkawap-a4f9ea2cd2f2"
},
{
"title": "LEARN ABOUT SYNTHETICS",
"img": "/marketing/synths.png",
Expand Down
4 changes: 3 additions & 1 deletion src/lang/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,9 @@ export default {
assetId: 'Asset ID',
},
explore: {
showOnlyMyPositions: 'Show only my positions',
showOnly: 'Show only {entities}',
myPositions: 'my positions',
synthetics: 'synthetic tokens',
},
dexSettings: {
title: 'Transaction settings',
Expand Down
12 changes: 6 additions & 6 deletions src/store/bridge/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function bridgeDataToHistoryItem(
context: ActionContext<any, any>,
{ date = Date.now(), payload = {}, ...params } = {}
): IBridgeTransaction {
const { getters, state, rootState, rootGetters } = bridgeActionContext(context);
const { getters, state, rootState } = bridgeActionContext(context);
const { isEthBridge, isEvmBridge } = getters;
const transactionState = isEthBridge ? WALLET_CONSTS.ETH_BRIDGE_STATES.INITIAL : BridgeTxStatus.Pending;
const externalNetwork = rootState.web3.networkSelected as BridgeNetworkId as any;
Expand All @@ -100,7 +100,7 @@ function bridgeDataToHistoryItem(
? BridgeNetworkType.Evm
: BridgeNetworkType.Sub;

return {
const data = {
type: (params as any).type ?? getters.operation,
amount: (params as any).amount ?? state.amountSend,
amount2: (params as any).amount2 ?? state.amountReceived,
Expand All @@ -110,12 +110,15 @@ function bridgeDataToHistoryItem(
endTime: date,
transactionState,
soraNetworkFee: (params as any).soraNetworkFee ?? state.soraNetworkFee,
parachainNetworkFee: (params as any).parachainNetworkFee ?? state.externalTransferFee,
externalNetworkFee: (params as any).externalNetworkFee,
externalNetwork,
externalNetworkType,
to: (params as any).to ?? getters.externalAccountFormatted,
payload,
};

return data;
}

async function getEvmNetworkFee(context: ActionContext<any, any>): Promise<void> {
Expand Down Expand Up @@ -461,10 +464,7 @@ const actions = defineActions({

if (getters.isSubBridge && getters.asset && getters.isRegisteredAsset) {
try {
const value = await subBridgeApi.soraParachainApi.getAssetMinimumAmount(
getters.asset.address,
subBridgeConnector.parachainAdapter.api
);
const value = await subBridgeConnector.parachainAdapter.getAssetMinimumAmount(getters.asset.address);
minLimit = FPNumber.fromCodecValue(value, getters.asset.externalDecimals);
} catch (error) {
console.error(error);
Expand Down
6 changes: 3 additions & 3 deletions src/store/settings/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function closeConnectionWithInfo() {

if (currentEndpoint && opened) {
await connection.close();
console.info('Disconnected from node', currentEndpoint);
console.info('[SORA] Disconnected from node', currentEndpoint);
}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ const actions = defineActions({
}
commit.setNodeRequest({ node, isReconnection });

console.info('Connection request to node', endpoint);
console.info('[SORA] Connection request to node', endpoint);

await closeConnectionWithInfo();

Expand All @@ -134,7 +134,7 @@ const actions = defineActions({

if (connectingNodeChanged()) return;

console.info('Connected to node', connection.endpoint);
console.info('[SORA] Connected to node', connection.endpoint);

const nodeChainGenesisHash = connection.api?.genesisHash.toHex();
// if connected node is custom node, we should check genesis hash
Expand Down
11 changes: 8 additions & 3 deletions src/utils/bridge/eth/classes/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,14 @@ export class EthBridgeHistory {
return history;
}

public async clearHistory(updateCallback?: FnWithoutArgs | AsyncFnWithoutArgs): Promise<void> {
public async clearHistory(
inProgressIds: Record<string, boolean>,
updateCallback?: FnWithoutArgs | AsyncFnWithoutArgs
): Promise<void> {
// don't remove history, what in progress
const ids = Object.keys(ethBridgeApi.history).filter((id) => !(id in inProgressIds));
ethBridgeApi.removeHistory(...ids);
this.historySyncTimestamp = 0;
ethBridgeApi.clearHistory();
await updateCallback?.();
}

Expand Down Expand Up @@ -420,7 +425,7 @@ export const updateEthBridgeHistory =
await ethBridgeHistory.init(ethBridgeContractAddress);

if (clearHistory) {
await ethBridgeHistory.clearHistory(updateCallback);
await ethBridgeHistory.clearHistory(inProgressIds, updateCallback);
}

await ethBridgeHistory.updateAccountHistory(
Expand Down
51 changes: 44 additions & 7 deletions src/utils/bridge/sub/classes/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,24 @@ export class SubAdapter {
this.endpoint = endpoint;
}

public setApi(api: ApiPromise): void {
console.info(`[${this.subNetwork}] Api injected`);
this.connection.api = api;
}

public async connect(): Promise<void> {
if (!this.connected && this.endpoint) {
if (!this.connected && !this.api && !this.connection.loading && this.endpoint) {
console.info(`[${this.subNetwork}] Connection request to node:`, this.endpoint);
await this.connection.open(this.endpoint);
await this.api.isReady;
console.info(`[${this.subNetwork}] Connected to node:`, this.endpoint);
}
await this.api.isReady;
}

public async stop(): Promise<void> {
if (this.connected) {
await this.connection.close();
console.info(`[${this.subNetwork}] Disconnected from node:`, this.endpoint);
}
}

Expand Down Expand Up @@ -122,6 +130,16 @@ export class SubAdapter {
}
}

class SoraParachainAdapter extends SubAdapter {
public async getAssetMinimumAmount(assetAddress: string): Promise<CodecString> {
await this.connect();

const value = await subBridgeApi.soraParachainApi.getAssetMinimumAmount(assetAddress, this.api);

return value;
}
}

class KusamaAdapter extends SubAdapter {
public async getTokenBalance(accountAddress: string, tokenAddress?: string): Promise<CodecString> {
return await this.getAccountBalance(accountAddress);
Expand Down Expand Up @@ -179,6 +197,10 @@ class KusamaAdapter extends SubAdapter {
try {
return await super.getNetworkFee(asset);
} catch {
// Hardcoded value for Rococo - 0.000125 ROC
if (this.subNetwork === SubNetwork.Rococo) {
return '125810197';
}
// Hardcoded value for Kusama - 0.0007 KSM
return '700000000';
}
Expand Down Expand Up @@ -206,19 +228,19 @@ export class SubNetworksConnector {
public network!: SubNetwork;
public parachainNetwork!: SubNetwork;
public networkAdapter!: SubAdapter;
public parachainAdapter!: SubAdapter;
public parachainAdapter!: SoraParachainAdapter;
public parachainId!: number;

public static endpoints: SubNetworkApps = {};

public readonly adapters = {
[SubNetwork.Rococo]: () => new KusamaAdapter(SubNetwork.Rococo),
[SubNetwork.Kusama]: () => new KusamaAdapter(SubNetwork.Kusama),
[SubNetwork.RococoSora]: () => new SubAdapter(SubNetwork.RococoSora),
[SubNetwork.KusamaSora]: () => new SubAdapter(SubNetwork.KusamaSora),
[SubNetwork.RococoSora]: () => new SoraParachainAdapter(SubNetwork.RococoSora),
[SubNetwork.KusamaSora]: () => new SoraParachainAdapter(SubNetwork.KusamaSora),
};

public getAdapterForNetwork(network: SubNetwork): SubAdapter {
public getAdapterForNetwork<T>(network: SubNetwork): T {
if (!(network in this.adapters)) {
throw new Error(`[${this.constructor.name}] Adapter for "${network}" network not implemented`);
}
Expand All @@ -233,12 +255,27 @@ export class SubNetworksConnector {
return adapter;
}

public async init(network: SubNetwork): Promise<void> {
/**
* Initialize params for substrate networks connector
* @param network External substrate network
* @param connector Existing bridge connector. Api connections will be reused, if networks matches
*/
public async init(network: SubNetwork, connector?: SubNetworksConnector): Promise<void> {
// Initialize options & adapters
this.network = network;
this.networkAdapter = this.getAdapterForNetwork(this.network);
this.parachainNetwork = this.networkAdapter.getSoraParachainNetwork();
this.parachainAdapter = this.getAdapterForNetwork(this.parachainNetwork);
this.parachainId = this.parachainAdapter.getSoraParachainId() as number;

if (!connector) return;
// Clone api instances, if networks matches
if (connector.networkAdapter.api && connector.networkAdapter.subNetwork === this.networkAdapter.subNetwork) {
this.networkAdapter.setApi(connector.networkAdapter.api.clone());
}
if (connector.parachainAdapter.api && connector.parachainAdapter.subNetwork === this.parachainAdapter.subNetwork) {
this.parachainAdapter.setApi(connector.parachainAdapter.api.clone());
}
}

/**
Expand Down
44 changes: 24 additions & 20 deletions src/utils/bridge/sub/classes/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import { ZeroStringValue } from '@/consts';
import { rootActionContext } from '@/store';
import { getBlockEventsByTxIndex } from '@/utils/bridge/common/utils';
import { subBridgeApi } from '@/utils/bridge/sub/api';
import { SubNetworksConnector } from '@/utils/bridge/sub/classes/adapter';
import { SubNetworksConnector, subBridgeConnector } from '@/utils/bridge/sub/classes/adapter';
import { getMessageAcceptedNonces, isMessageDispatchedNonces, formatSubAddress } from '@/utils/bridge/sub/utils';

import type { ApiPromise } from '@polkadot/api';
import type { NetworkFeesObject } from '@sora-substrate/util';
import type { RegisteredAccountAsset } from '@sora-substrate/util/build/assets/types';
import type { SubNetwork } from '@sora-substrate/util/build/bridgeProxy/sub/consts';
import type { SubHistory } from '@sora-substrate/util/build/bridgeProxy/sub/types';
Expand Down Expand Up @@ -64,14 +63,18 @@ class SubBridgeHistory extends SubNetworksConnector {
return this.networkAdapter.api;
}

public async clearHistory(updateCallback?: FnWithoutArgs | AsyncFnWithoutArgs): Promise<void> {
subBridgeApi.clearHistory();
public async clearHistory(
inProgressIds: Record<string, boolean>,
updateCallback?: FnWithoutArgs | AsyncFnWithoutArgs
): Promise<void> {
// don't remove history, what in progress
const ids = Object.keys(subBridgeApi.history).filter((id) => !(id in inProgressIds));
subBridgeApi.removeHistory(...ids);
await updateCallback?.();
}

public async updateAccountHistory(
address: string,
networkFees: NetworkFeesObject,
inProgressIds: Record<string, boolean>,
assetDataByAddress: (address?: Nullable<string>) => Nullable<RegisteredAccountAsset>,
updateCallback?: FnWithoutArgs | AsyncFnWithoutArgs
Expand All @@ -93,7 +96,7 @@ class SubBridgeHistory extends SubNetworksConnector {

await this.start();

const historyItemData = await this.txDataToHistory(tx, networkFees, assetDataByAddress);
const historyItemData = await this.txDataToHistory(tx, assetDataByAddress);

if (!historyItemData) continue;

Expand All @@ -113,7 +116,6 @@ class SubBridgeHistory extends SubNetworksConnector {

private async txDataToHistory(
tx: BridgeTransactionData,
networkFees: NetworkFeesObject,
assetDataByAddress: (address?: Nullable<string>) => Nullable<RegisteredAccountAsset>
): Promise<Nullable<SubHistory>> {
const id = tx.soraHash;
Expand Down Expand Up @@ -237,13 +239,22 @@ class SubBridgeHistory extends SubNetworksConnector {
this.externalApi.events.balances.Deposit.is(event) &&
subBridgeApi.formatAddress(event.data.who.toString()) === to
);
const received = balancesDepositEvent.event.data.amount.toString();
const sended = FPNumber.fromCodecValue(tx.amount, asset?.decimals);
const received = FPNumber.fromCodecValue(
balancesDepositEvent.event.data.amount.toString(),
asset?.externalDecimals
);
const parachainNetworkFee = new FPNumber(
sended.sub(received).toString(),
asset?.externalDecimals
).toCodecString();

history.soraNetworkFee = soraFeeEvent.event.data[1].toString();
history.parachainNetworkFee = parachainNetworkFee;
history.externalNetworkFee = ZeroStringValue;
history.externalBlockId = blockId;
history.externalBlockHeight = n;
history.amount2 = FPNumber.fromCodecValue(received, asset?.externalDecimals).toString();
history.amount2 = received.toString();
history.to = formatSubAddress(tx.externalAccount, this.externalApi.registry.chainSS58 as number);
break;
} catch {
Expand Down Expand Up @@ -290,7 +301,7 @@ class SubBridgeHistory extends SubNetworksConnector {
history.externalNetworkFee = feeEvent.event.data[1].toString();
history.externalBlockId = blockId;
history.externalBlockHeight = n;
history.to = formatSubAddress(signer, this.externalApi.registry.chainSS58 as number);
history.to = formatSubAddress(signer, this.soraApi.registry.chainSS58 as number);
return;
} catch {
continue;
Expand All @@ -313,7 +324,6 @@ export const updateSubBridgeHistory =
const {
wallet: {
account: { address },
settings: { networkFees },
},
web3: { networkSelected },
bridge: { inProgressIds },
Expand All @@ -324,19 +334,13 @@ export const updateSubBridgeHistory =
const assetDataByAddress = rootGetters.assets.assetDataByAddress;
const subBridgeHistory = new SubBridgeHistory();

await subBridgeHistory.init(networkSelected as SubNetwork);
await subBridgeHistory.init(networkSelected as SubNetwork, subBridgeConnector);

if (clearHistory) {
await subBridgeHistory.clearHistory(updateCallback);
await subBridgeHistory.clearHistory(inProgressIds, updateCallback);
}

await subBridgeHistory.updateAccountHistory(
address,
networkFees,
inProgressIds,
assetDataByAddress,
updateCallback
);
await subBridgeHistory.updateAccountHistory(address, inProgressIds, assetDataByAddress, updateCallback);
} catch (error) {
console.error(error);
}
Expand Down
Loading

0 comments on commit ddb0b77

Please sign in to comment.