From 6969c270874b69a6f308b28cfe9acaf4b21d5bb5 Mon Sep 17 00:00:00 2001 From: Tuditi Date: Fri, 22 Mar 2024 15:50:35 +0100 Subject: [PATCH 01/25] feat: enable IOTA EVM --- .../default-chain-configurations.constant.ts | 12 ++++++++++++ .../network/constants/default-coin-type.constant.ts | 1 + .../src/lib/core/network/enums/evm-chain-id.enum.ts | 1 + .../core/network/enums/supported-network-id.enum.ts | 1 + 4 files changed, 15 insertions(+) diff --git a/packages/shared/src/lib/core/network/constants/default-chain-configurations.constant.ts b/packages/shared/src/lib/core/network/constants/default-chain-configurations.constant.ts index 5193fce118..5bb119d99c 100644 --- a/packages/shared/src/lib/core/network/constants/default-chain-configurations.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-chain-configurations.constant.ts @@ -3,6 +3,18 @@ import { ChainType, EvmChainId, NetworkNamespace, StardustNetworkId, SupportedNe import { ChainConfiguration } from '../types' export const DEFAULT_CHAIN_CONFIGURATIONS: Readonly<{ [id in StardustNetworkId]?: ChainConfiguration }> = { + [SupportedNetworkId.Iota]: { + id: SupportedNetworkId.IotaEvm, + type: ChainType.Iscp, + name: 'IOTA EVM', + chainId: EvmChainId.IotaEvm, + namespace: NetworkNamespace.Evm, + coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.IotaEvm], + aliasAddress: 'iota1pzt3mstq6khgc3tl0mwuzk3eqddkryqnpdxmk4nr25re2466uxwm28qqxu5', + rpcEndpoint: 'https://json-rpc.evm.iotaledger.net/', + apiEndpoint: 'https://api.evm.iotaledger.net/', + explorerUrl: 'https://iota-evm.blockscout.com/', + }, [SupportedNetworkId.Shimmer]: { id: SupportedNetworkId.ShimmerEvm, type: ChainType.Iscp, diff --git a/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts b/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts index 006d9ff222..82b9642c25 100644 --- a/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts @@ -9,6 +9,7 @@ export const DEFAULT_COIN_TYPE: Readonly<{ [id in SupportedNetworkId]: number }> [SupportedNetworkId.Iota]: IOTA_COIN_TYPE, [SupportedNetworkId.Shimmer]: SHIMMER_COIN_TYPE, [SupportedNetworkId.Testnet]: TEST_COIN_TYPE, + [SupportedNetworkId.IotaEvm]: ETHEREUM_COIN_TYPE, [SupportedNetworkId.ShimmerEvm]: ETHEREUM_COIN_TYPE, [SupportedNetworkId.TestnetEvm]: ETHEREUM_COIN_TYPE, } diff --git a/packages/shared/src/lib/core/network/enums/evm-chain-id.enum.ts b/packages/shared/src/lib/core/network/enums/evm-chain-id.enum.ts index f08d509b71..764a8a9a6d 100644 --- a/packages/shared/src/lib/core/network/enums/evm-chain-id.enum.ts +++ b/packages/shared/src/lib/core/network/enums/evm-chain-id.enum.ts @@ -1,4 +1,5 @@ export enum EvmChainId { + IotaEvm = '8822', ShimmerEvm = '148', TestnetEvm = '1073', } diff --git a/packages/shared/src/lib/core/network/enums/supported-network-id.enum.ts b/packages/shared/src/lib/core/network/enums/supported-network-id.enum.ts index 3bb8372fa1..95f9f76ecd 100644 --- a/packages/shared/src/lib/core/network/enums/supported-network-id.enum.ts +++ b/packages/shared/src/lib/core/network/enums/supported-network-id.enum.ts @@ -9,6 +9,7 @@ export enum StardustNetworkId { } export enum EvmNetworkId { + IotaEvm = `${NetworkNamespace.Evm}:${EvmChainId.IotaEvm}`, ShimmerEvm = `${NetworkNamespace.Evm}:${EvmChainId.ShimmerEvm}`, TestnetEvm = `${NetworkNamespace.Evm}:${EvmChainId.TestnetEvm}`, } From 94433adf30e037453c115229c9dc91ff1a0785b4 Mon Sep 17 00:00:00 2001 From: Tuditi Date: Fri, 22 Mar 2024 17:17:11 +0100 Subject: [PATCH 02/25] fix: improve l2->l1 SDR --- .../constants/l2-to-l1-storage-deposit-buffer.constant.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/src/lib/core/layer-2/constants/l2-to-l1-storage-deposit-buffer.constant.ts b/packages/shared/src/lib/core/layer-2/constants/l2-to-l1-storage-deposit-buffer.constant.ts index 47d113c005..ee3b6cfd5d 100644 --- a/packages/shared/src/lib/core/layer-2/constants/l2-to-l1-storage-deposit-buffer.constant.ts +++ b/packages/shared/src/lib/core/layer-2/constants/l2-to-l1-storage-deposit-buffer.constant.ts @@ -1,6 +1,6 @@ import { SendFlowType } from '@core/wallet/enums' export const L2_TO_L1_STORAGE_DEPOSIT_BUFFER: { [key in SendFlowType]?: bigint } = { - [SendFlowType.TokenUnwrap]: BigInt(56_500), + [SendFlowType.TokenUnwrap]: BigInt(141_250), [SendFlowType.NftUnwrap]: BigInt(3_500), } From 3f5a5cef6375aae4ad0ffc59d00ae0b7e47795cb Mon Sep 17 00:00:00 2001 From: Tuditi Date: Mon, 15 Apr 2024 11:36:12 +0200 Subject: [PATCH 03/25] feat: add explorer URLs --- .../core/network/constants/default-explorer-urls.constant.ts | 1 + .../core/network/constants/explorer-endpoints.constant.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts b/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts index 41c66e3611..2db06adf5f 100644 --- a/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts @@ -4,6 +4,7 @@ export const DEFAULT_EXPLORER_URLS: Readonly<{ [key in SupportedNetworkId]: stri [SupportedNetworkId.Iota]: 'https://explorer.iota.org', [SupportedNetworkId.Shimmer]: 'https://explorer.shimmer.network', [SupportedNetworkId.Testnet]: 'https://explorer.shimmer.network', + [SupportedNetworkId.IotaEvm]: 'https://explorer.evm.shimmer.network', [SupportedNetworkId.ShimmerEvm]: 'https://explorer.evm.shimmer.network', [SupportedNetworkId.TestnetEvm]: 'https://explorer.evm.testnet.shimmer.network', } diff --git a/packages/shared/src/lib/core/network/constants/explorer-endpoints.constant.ts b/packages/shared/src/lib/core/network/constants/explorer-endpoints.constant.ts index ad9e27201a..3344d0707d 100644 --- a/packages/shared/src/lib/core/network/constants/explorer-endpoints.constant.ts +++ b/packages/shared/src/lib/core/network/constants/explorer-endpoints.constant.ts @@ -22,6 +22,11 @@ export const EXPLORER_ENDPOINTS: Readonly<{ [key in SupportedNetworkId]: { [key [ExplorerEndpoint.Foundry]: `testnet/${ExplorerEndpoint.Foundry}`, [ExplorerEndpoint.Address]: 'testnet/addr', }, + [SupportedNetworkId.IotaEvm]: { + [ExplorerEndpoint.Transaction]: 'tx', + [ExplorerEndpoint.Token]: ExplorerEndpoint.Token, + [ExplorerEndpoint.Address]: ExplorerEndpoint.Address, + }, [SupportedNetworkId.ShimmerEvm]: { [ExplorerEndpoint.Transaction]: 'tx', [ExplorerEndpoint.Token]: ExplorerEndpoint.Token, From abefaff86f19ec45c18437a06724471aeb35298a Mon Sep 17 00:00:00 2001 From: Tuditi Date: Mon, 15 Apr 2024 12:15:53 +0200 Subject: [PATCH 04/25] feat: check if explorer URL exists --- .../src/lib/core/layer-2/actions/checkForUntrackedTokens.ts | 2 +- .../shared/src/lib/core/nfts/actions/checkForUntrackedNfts.ts | 2 +- .../actions/fetchAndPersistTransactionsForAccounts.ts | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/shared/src/lib/core/layer-2/actions/checkForUntrackedTokens.ts b/packages/shared/src/lib/core/layer-2/actions/checkForUntrackedTokens.ts index 1ba2ca6416..f0568e27f1 100644 --- a/packages/shared/src/lib/core/layer-2/actions/checkForUntrackedTokens.ts +++ b/packages/shared/src/lib/core/layer-2/actions/checkForUntrackedTokens.ts @@ -9,7 +9,7 @@ export function checkForUntrackedTokens(account: IAccountState, addPreviouslyUnt const evmNetworks = getEvmNetworks() evmNetworks?.forEach(async (evmNetwork) => { const evmAddress = account.evmAddresses[evmNetwork.coinType] - if (!evmAddress) { + if (!evmAddress || !evmNetwork.explorerUrl) { return } const networkId = evmNetwork.id diff --git a/packages/shared/src/lib/core/nfts/actions/checkForUntrackedNfts.ts b/packages/shared/src/lib/core/nfts/actions/checkForUntrackedNfts.ts index 0d4275572e..edfa8f0dac 100644 --- a/packages/shared/src/lib/core/nfts/actions/checkForUntrackedNfts.ts +++ b/packages/shared/src/lib/core/nfts/actions/checkForUntrackedNfts.ts @@ -23,7 +23,7 @@ export async function checkForUntrackedNfts(account: IAccountState): Promise { const networks = getEvmNetworks() for (const network of networks) { + if (!network.explorerUrl) { + continue + } + const networkId = network.id for (const account of accounts) { try { From ebbb05709c205671bd32d916a95aa2bb236b9568 Mon Sep 17 00:00:00 2001 From: Tuditi Date: Mon, 15 Apr 2024 14:58:19 +0200 Subject: [PATCH 05/25] fix: use correct explorer --- .../core/network/constants/default-explorer-urls.constant.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts b/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts index f23b1331fa..412533459a 100644 --- a/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts @@ -5,7 +5,7 @@ export const DEFAULT_EXPLORER_URLS: Readonly<{ [key in NetworkId]?: string }> = [SupportedNetworkId.Iota]: 'https://explorer.iota.org', [SupportedNetworkId.Shimmer]: 'https://explorer.shimmer.network', [SupportedNetworkId.Testnet]: 'https://explorer.shimmer.network', - [SupportedNetworkId.IotaEvm]: 'https://explorer.evm.shimmer.network', + [SupportedNetworkId.IotaEvm]: 'https://iota-evm.blockscout.com', [SupportedNetworkId.ShimmerEvm]: 'https://explorer.evm.shimmer.network', [SupportedNetworkId.TestnetEvm]: 'https://explorer.evm.testnet.shimmer.network', } From a4011f9386e2a5ec8bbac02de438bae6d76c11b8 Mon Sep 17 00:00:00 2001 From: Tuditi Date: Mon, 15 Apr 2024 22:30:19 +0200 Subject: [PATCH 06/25] feat: use virtual byte cost for calculating buffer --- .../components/EvmTransactionSummary.svelte | 22 +++++++++---------- .../src/lib/core/layer-2/constants/index.ts | 1 - ...2-to-l1-storage-deposit-buffer.constant.ts | 6 ----- ...ulateEstimatedGasFeeFromTransactionData.ts | 4 ++-- .../calculateMaxGasFeeFromTransactionData.ts | 4 ++-- .../utils/getL2ToL1StorageDepositBuffer.ts | 19 ++++++++++++++++ .../src/lib/core/layer-2/utils/index.ts | 1 + .../src/lib/core/nfts/utils/isIrc27Nft.ts | 4 ++-- 8 files changed, 37 insertions(+), 24 deletions(-) delete mode 100644 packages/shared/src/lib/core/layer-2/constants/l2-to-l1-storage-deposit-buffer.constant.ts create mode 100644 packages/shared/src/lib/core/layer-2/utils/getL2ToL1StorageDepositBuffer.ts diff --git a/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte b/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte index 2ba3cf3302..d03193ab79 100644 --- a/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte +++ b/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte @@ -1,9 +1,9 @@ - - + {#if showTooltip && networkName} From ce43462a751d4b3914dacd8ff00c9312fb2b6af1 Mon Sep 17 00:00:00 2001 From: Tuditi Date: Tue, 23 Apr 2024 10:49:31 +0200 Subject: [PATCH 10/25] chore: interface updates --- .../src/components/avatars/TokenAvatar.svelte | 3 +++ .../core/network/classes/isc-chain.class.ts | 20 +++++++++++-------- .../interfaces/evm-network.interface.ts | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/shared/src/components/avatars/TokenAvatar.svelte b/packages/shared/src/components/avatars/TokenAvatar.svelte index c78d483fe8..cc3a2f499a 100644 --- a/packages/shared/src/components/avatars/TokenAvatar.svelte +++ b/packages/shared/src/components/avatars/TokenAvatar.svelte @@ -44,6 +44,9 @@ [SupportedNetworkId.Testnet]: { [BASE_TOKEN_ID]: 'shimmer-background', }, + [SupportedNetworkId.IotaEvm]: { + [BASE_TOKEN_ID]: '#FFFFFF', + }, [SupportedNetworkId.ShimmerEvm]: { [BASE_TOKEN_ID]: 'shimmer-background', }, diff --git a/packages/shared/src/lib/core/network/classes/isc-chain.class.ts b/packages/shared/src/lib/core/network/classes/isc-chain.class.ts index b3fed8200b..548d0d2b5f 100644 --- a/packages/shared/src/lib/core/network/classes/isc-chain.class.ts +++ b/packages/shared/src/lib/core/network/classes/isc-chain.class.ts @@ -62,6 +62,8 @@ export class IscChain implements IIscChain { this.apiEndpoint = apiEndpoint this._chainApi = `${apiEndpoint}v1/chains/${aliasAddress}` + + void this.getMetadata() } catch (err) { console.error(err) throw new Error('Failed to construct isc Chain!') @@ -88,12 +90,16 @@ export class IscChain implements IIscChain { return new this.provider.eth.Contract(abi, address) } - async getMetadata(): Promise { - if (this._metadata) { - return Promise.resolve(this._metadata) - } else { - this._metadata = await this.fetchChainMetadata() - return Promise.resolve(this._metadata) + async getMetadata(): Promise { + try { + if (this._metadata) { + return Promise.resolve(this._metadata) + } else { + this._metadata = await this.fetchChainMetadata() + return Promise.resolve(this._metadata) + } + } catch (err) { + console.error(err) } } @@ -114,8 +120,6 @@ export class IscChain implements IIscChain { } async getGasFeeEstimate(hex: string): Promise { - // TODO move into constructor once derived store is removed and handle errors appropriately. - await this.getMetadata() const URL = `${this._chainApi}/estimategas-onledger` const body = JSON.stringify({ outputBytes: hex }) diff --git a/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts b/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts index 5573dd964a..419ace8284 100644 --- a/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts +++ b/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts @@ -13,7 +13,7 @@ export interface IIscChain extends IEvmNetwork { aliasAddress: string getGasFeeEstimate(hex: string): Promise - getMetadata(): Promise + getMetadata(): Promise } export interface IEvmNetwork extends IBaseNetwork { From 7942019bf0019a60ddb425b96bf278032cc1ff64 Mon Sep 17 00:00:00 2001 From: Tuditi Date: Tue, 23 Apr 2024 10:51:10 +0200 Subject: [PATCH 11/25] feat: support custom networks and handle runtime error --- .../components/EvmTransactionSummary.svelte | 34 ++++++++++++------- .../utils/getL2ToL1StorageDepositBuffer.ts | 21 +++++++++--- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte b/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte index d03193ab79..17cd81fc44 100644 --- a/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte +++ b/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte @@ -9,6 +9,7 @@ import { SendFlowParameters, SendFlowType, TokenTransferData } from '@core/wallet' import { TransactionAssetSection } from '@ui' import EvmTransactionDetails from './EvmTransactionDetails.svelte' + import { handleError } from '@core/error/handlers' export let transaction: EvmTransactionData export let sendFlowParameters: SendFlowParameters @@ -28,20 +29,27 @@ $: storageDeposit = getTransactionStorageDeposit(sendFlowParameters) ?? BigInt(0) function getTransactionStorageDeposit(_sendFlowParameters: SendFlowParameters): bigint | undefined { - const { type, destinationNetworkId } = _sendFlowParameters - if (type === SendFlowType.TokenTransfer) { - if (destinationNetworkId && destinationNetworkId !== _sendFlowParameters?.tokenTransfer?.token.networkId) { - return getL2ToL1StorageDepositBuffer(SendFlowType.TokenUnwrap, destinationNetworkId) - } - } else if (type === SendFlowType.NftTransfer) { - if ( - destinationNetworkId && - destinationNetworkId !== _sendFlowParameters.nft?.networkId && - isIrc27Nft(_sendFlowParameters.nft) - ) { - const buffer = getL2ToL1StorageDepositBuffer(SendFlowType.NftUnwrap, destinationNetworkId) - return (_sendFlowParameters.nft?.storageDeposit ?? BigInt(0)) + buffer + try { + const { type, destinationNetworkId } = _sendFlowParameters + if (type === SendFlowType.TokenTransfer) { + if ( + destinationNetworkId && + destinationNetworkId !== _sendFlowParameters?.tokenTransfer?.token.networkId + ) { + return getL2ToL1StorageDepositBuffer(SendFlowType.TokenUnwrap, destinationNetworkId) + } + } else if (type === SendFlowType.NftTransfer) { + if ( + destinationNetworkId && + destinationNetworkId !== _sendFlowParameters.nft?.networkId && + isIrc27Nft(_sendFlowParameters.nft) + ) { + const buffer = getL2ToL1StorageDepositBuffer(SendFlowType.NftUnwrap, destinationNetworkId) + return (_sendFlowParameters.nft?.storageDeposit ?? BigInt(0)) + buffer + } } + } catch (err) { + handleError(err) } } diff --git a/packages/shared/src/lib/core/layer-2/utils/getL2ToL1StorageDepositBuffer.ts b/packages/shared/src/lib/core/layer-2/utils/getL2ToL1StorageDepositBuffer.ts index 6236b987ea..cc58ad95e6 100644 --- a/packages/shared/src/lib/core/layer-2/utils/getL2ToL1StorageDepositBuffer.ts +++ b/packages/shared/src/lib/core/layer-2/utils/getL2ToL1StorageDepositBuffer.ts @@ -1,8 +1,10 @@ +import { nodeInfo } from '@core/network' import { DEFAULT_PROTOCOL } from '@core/network/constants' import { NetworkId } from '@core/network/types' import { SendFlowType } from '@core/wallet/enums' +import { get } from 'svelte/store' -const L2_TO_L1_STORAGE_DEPOSIT_BUFFER_BYTE_COST: { [key in UnwrapSendFlow]: bigint } = { +const L2_TO_L1_STORAGE_DEPOSIT_BUFFER_BYTES: { [key in UnwrapSendFlow]: bigint } = { [SendFlowType.TokenUnwrap]: BigInt(565), [SendFlowType.NftUnwrap]: BigInt(35), } @@ -10,10 +12,21 @@ const L2_TO_L1_STORAGE_DEPOSIT_BUFFER_BYTE_COST: { [key in UnwrapSendFlow]: bigi type UnwrapSendFlow = SendFlowType.TokenUnwrap | SendFlowType.NftUnwrap export function getL2ToL1StorageDepositBuffer(type: UnwrapSendFlow, network: NetworkId): bigint { - const vByteCost = DEFAULT_PROTOCOL[network]?.rentStructure.vByteCost - if (!vByteCost) { + const actualVByteCost = get(nodeInfo)?.protocol.rentStructure.vByteCost + let expectedVByteCost = DEFAULT_PROTOCOL[network]?.rentStructure.vByteCost + + // TODO: Validate byte cost returned by node + if (!expectedVByteCost && !actualVByteCost) { throw new Error(`Virtual byte cost for ${network} is undefined!`) + // } else if (!actualVByteCost) { + // throw new Error('Node does not return virtual byte cost') + } else if (!expectedVByteCost) { + expectedVByteCost = actualVByteCost } - return BigInt(vByteCost) * L2_TO_L1_STORAGE_DEPOSIT_BUFFER_BYTE_COST[type] + // if (expectedVByteCost !== actualVByteCost) { + // throw new Error('Virtual byte cost from the node differs from the expected values') + // } + + return BigInt(expectedVByteCost) * L2_TO_L1_STORAGE_DEPOSIT_BUFFER_BYTES[type] } From b284a3a2d3720994c87cfc263163ac3ec37b27dc Mon Sep 17 00:00:00 2001 From: Tuditi Date: Tue, 23 Apr 2024 16:48:52 +0200 Subject: [PATCH 12/25] fix: use correct encoding --- .../actions/getLayer2MetadataForTransfer.ts | 13 ++++++-- .../core/network/classes/isc-chain.class.ts | 31 ++++++++----------- .../interfaces/evm-network.interface.ts | 3 +- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/packages/shared/src/lib/core/layer-2/actions/getLayer2MetadataForTransfer.ts b/packages/shared/src/lib/core/layer-2/actions/getLayer2MetadataForTransfer.ts index 134686eb75..cc8965b83c 100644 --- a/packages/shared/src/lib/core/layer-2/actions/getLayer2MetadataForTransfer.ts +++ b/packages/shared/src/lib/core/layer-2/actions/getLayer2MetadataForTransfer.ts @@ -16,15 +16,22 @@ export function getLayer2MetadataForTransfer(sendFlowParameters: SendFlowParamet const address = sendFlowParameters.recipient?.address ?? '' const encodedAddress = encodeAddress(address.toLowerCase(), iscChain) - const estimatedGas = sendFlowParameters.gasFee ?? BigInt(0) - const gasLimit = Math.floor(Number(estimatedGas) * GAS_LIMIT_MULTIPLIER) + const gasFee = sendFlowParameters.gasFee ?? BigInt(0) + const gasPerToken = iscChain.getMetadata()?.gasFeePolicy.gasPerToken + let gasLimit: number + if (gasPerToken) { + // More information can be found here: https://wiki.iota.org/isc/reference/core-contracts/governance/#ratio32 + gasLimit = (Number(gasFee) * gasPerToken['a']) / gasPerToken['b'] + } else { + gasLimit = Number(gasFee) * GAS_LIMIT_MULTIPLIER + } metadataStream.writeUInt8('senderContract', EXTERNALLY_OWNED_ACCOUNT) metadataStream.writeUInt32('targetContract', ACCOUNTS_CONTRACT) metadataStream.writeUInt32('contractFunction', TRANSFER_ALLOWANCE) // Gas budget is the ISC equivalent of gas limit in ethereum and what we use throughout the code - metadataStream.writeUInt64SpecialEncoding('gasLimit', BigInt(gasLimit)) + metadataStream.writeUInt64SpecialEncoding('gasLimit', BigInt(Math.floor(gasLimit))) const smartContractParameters = Object.entries({ a: encodedAddress }) const parameters = encodeSmartContractParameters(smartContractParameters) diff --git a/packages/shared/src/lib/core/network/classes/isc-chain.class.ts b/packages/shared/src/lib/core/network/classes/isc-chain.class.ts index 548d0d2b5f..47067742d5 100644 --- a/packages/shared/src/lib/core/network/classes/isc-chain.class.ts +++ b/packages/shared/src/lib/core/network/classes/isc-chain.class.ts @@ -11,7 +11,6 @@ import { IBlock, IEvmNetworkStatus, IIscChainConfiguration, IIscChainMetadata, I import { evmNetworkStatuses } from '../stores' import { CoinType } from '@iota/sdk/out/types' import { EvmNetworkId, Web3Provider } from '../types' -import { Converter } from '@core/utils' export class IscChain implements IIscChain { public readonly provider: Web3Provider @@ -63,7 +62,7 @@ export class IscChain implements IIscChain { this._chainApi = `${apiEndpoint}v1/chains/${aliasAddress}` - void this.getMetadata() + void this.setMetadata() } catch (err) { console.error(err) throw new Error('Failed to construct isc Chain!') @@ -90,19 +89,18 @@ export class IscChain implements IIscChain { return new this.provider.eth.Contract(abi, address) } - async getMetadata(): Promise { + async setMetadata(): Promise { try { - if (this._metadata) { - return Promise.resolve(this._metadata) - } else { - this._metadata = await this.fetchChainMetadata() - return Promise.resolve(this._metadata) - } + this._metadata = await this.fetchChainMetadata() } catch (err) { console.error(err) } } + getMetadata(): IIscChainMetadata | undefined { + return this._metadata + } + /** * CAUTION: The API endpoint used by this method is not available * with the public ShimmerEVM node URL (b/c it's actually just @@ -119,9 +117,9 @@ export class IscChain implements IIscChain { return this.provider.eth.getBlock(number) } - async getGasFeeEstimate(hex: string): Promise { + async getGasFeeEstimate(outputBytes: string): Promise { const URL = `${this._chainApi}/estimategas-onledger` - const body = JSON.stringify({ outputBytes: hex }) + const body = JSON.stringify({ outputBytes }) const requestInit: RequestInit = { method: 'POST', @@ -136,15 +134,12 @@ export class IscChain implements IIscChain { const data = await response.json() if (response.status === 200) { - // More information can be found here: https://wiki.iota.org/isc/reference/core-contracts/governance/#ratio32 - const gasPerToken = this._metadata?.gasFeePolicy.gasPerToken ?? {} - const subunitPerGas = (gasPerToken['a'] ?? 1) / (gasPerToken['b'] ?? 1) - const gasFeeEstimate = Converter.bigIntLikeToBigInt(data.gasFeeCharged * subunitPerGas) - if (gasFeeEstimate === BigInt(0)) { - throw new Error(`Gas fee has an invalid value: ${gasFeeEstimate}!`) + const gasFee = BigInt(data.gasFeeCharged) + if (gasFee === BigInt(0)) { + throw new Error(`Gas fee has an invalid value: ${gasFee}!`) } - return gasFeeEstimate + return gasFee } else { throw new Error(data) } diff --git a/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts b/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts index 419ace8284..989b7a9b27 100644 --- a/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts +++ b/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts @@ -13,7 +13,8 @@ export interface IIscChain extends IEvmNetwork { aliasAddress: string getGasFeeEstimate(hex: string): Promise - getMetadata(): Promise + getMetadata(): IIscChainMetadata | undefined + setMetadata(): Promise } export interface IEvmNetwork extends IBaseNetwork { From 3f6c0f051848e6a16c8a33ef172fadeaf215b7d0 Mon Sep 17 00:00:00 2001 From: Tuditi Date: Wed, 24 Apr 2024 10:05:11 +0200 Subject: [PATCH 13/25] feat: use new explorer URL --- .../core/network/constants/default-explorer-urls.constant.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts b/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts index 412533459a..361cf64550 100644 --- a/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts @@ -5,7 +5,7 @@ export const DEFAULT_EXPLORER_URLS: Readonly<{ [key in NetworkId]?: string }> = [SupportedNetworkId.Iota]: 'https://explorer.iota.org', [SupportedNetworkId.Shimmer]: 'https://explorer.shimmer.network', [SupportedNetworkId.Testnet]: 'https://explorer.shimmer.network', - [SupportedNetworkId.IotaEvm]: 'https://iota-evm.blockscout.com', + [SupportedNetworkId.IotaEvm]: 'https://explorer.evm.iota.org', [SupportedNetworkId.ShimmerEvm]: 'https://explorer.evm.shimmer.network', [SupportedNetworkId.TestnetEvm]: 'https://explorer.evm.testnet.shimmer.network', } From 096c20de1e3a7d2f3703b7714174dbd48b78865d Mon Sep 17 00:00:00 2001 From: Tuditi Date: Wed, 24 Apr 2024 15:10:28 +0200 Subject: [PATCH 14/25] fix: sending native tokens to L2 for accounts without a balance --- .../src/lib/core/layer-2/utils/fetchIscAssetsForAccount.ts | 1 + packages/shared/src/lib/core/utils/convert.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/shared/src/lib/core/layer-2/utils/fetchIscAssetsForAccount.ts b/packages/shared/src/lib/core/layer-2/utils/fetchIscAssetsForAccount.ts index 0c98db3e5f..f90ebb5411 100644 --- a/packages/shared/src/lib/core/layer-2/utils/fetchIscAssetsForAccount.ts +++ b/packages/shared/src/lib/core/layer-2/utils/fetchIscAssetsForAccount.ts @@ -53,6 +53,7 @@ async function getL2NativeTokenBalancesForAddress(evmAddress: string, iscChain: nativeTokenResult.items?.forEach((item) => (nativeTokens[item.key] = Converter.bigIntLikeToBigInt(item.value))) return nativeTokens } catch (e) { + console.error(e) return {} } } diff --git a/packages/shared/src/lib/core/utils/convert.ts b/packages/shared/src/lib/core/utils/convert.ts index 16fc127245..f25d1b90e4 100644 --- a/packages/shared/src/lib/core/utils/convert.ts +++ b/packages/shared/src/lib/core/utils/convert.ts @@ -276,6 +276,7 @@ export class Converter { if (ArrayBuffer.isView(number)) { return bytesToBigInt(number) } else { + number = number === '0x' ? '0x0' : number return BigInt(String(number ?? '0')) } } From 40c0b4ad36a30d16c6c286593786f63e3b8eb787 Mon Sep 17 00:00:00 2001 From: Tuditi Date: Thu, 2 May 2024 21:38:06 +0200 Subject: [PATCH 15/25] Revert "feat: enable IOTA EVM" This reverts commit 6969c270874b69a6f308b28cfe9acaf4b21d5bb5. --- .../src/lib/core/network/constants/default-coin-type.constant.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts b/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts index dafaadd30e..9a1fe25891 100644 --- a/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts @@ -10,7 +10,6 @@ export const DEFAULT_COIN_TYPE: Readonly<{ [id in NetworkId]: number }> = { [SupportedNetworkId.Iota]: IOTA_COIN_TYPE, [SupportedNetworkId.Shimmer]: SHIMMER_COIN_TYPE, [SupportedNetworkId.Testnet]: TEST_COIN_TYPE, - [SupportedNetworkId.IotaEvm]: ETHEREUM_COIN_TYPE, [SupportedNetworkId.ShimmerEvm]: ETHEREUM_COIN_TYPE, [SupportedNetworkId.TestnetEvm]: ETHEREUM_COIN_TYPE, [SupportedNetworkId.Ethereum]: ETHEREUM_COIN_TYPE, From b60fdd1ceb445f7f2aa6027c4b199ba5d6b6832b Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Sun, 5 May 2024 21:43:57 +0100 Subject: [PATCH 16/25] fix: type --- .../constants/default-isc-chains-configurations.constant.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts b/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts index 4edce15f67..71c7218c18 100644 --- a/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts @@ -8,7 +8,7 @@ import { SupportedIscNetworkId, SupportedNetworkId, SupportedStardustNetworkId } export const DEFAULT_ISC_CHAINS_CONFIGURATIONS: Readonly<{ [id in StardustNetworkId]?: IIscChainConfiguration }> = { [SupportedStardustNetworkId.Iota]: { id: SupportedIscNetworkId.IotaEvm, - type: EvmNetworkType.Isc, + type: NetworkType.Isc, name: 'IOTA EVM', chainId: ChainId.IotaEvm, namespace: NetworkNamespace.Evm, From 9766c32b327fbe5f25ab65baf31efb9b46630a61 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Sun, 5 May 2024 21:47:05 +0100 Subject: [PATCH 17/25] update iota evm colour --- packages/shared/src/components/avatars/NetworkAvatar.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/src/components/avatars/NetworkAvatar.svelte b/packages/shared/src/components/avatars/NetworkAvatar.svelte index e96032e491..0b1e7448bc 100644 --- a/packages/shared/src/components/avatars/NetworkAvatar.svelte +++ b/packages/shared/src/components/avatars/NetworkAvatar.svelte @@ -13,7 +13,7 @@ [SupportedNetworkId.Iota]: '#000000', [SupportedNetworkId.Shimmer]: 'shimmer-background', [SupportedNetworkId.Testnet]: 'shimmer-background', - [SupportedNetworkId.IotaEvm]: '#FFFFFF', + [SupportedNetworkId.IotaEvm]: '#0A0FB0', [SupportedNetworkId.ShimmerEvm]: 'shimmer-background', [SupportedNetworkId.TestnetEvm]: 'text-secondary', } From a94129a7857efa1091a46f5debd5fcac5a65f69e Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Sun, 5 May 2024 21:47:43 +0100 Subject: [PATCH 18/25] add evm explorer url --- .../core/network/constants/default-explorer-urls.constant.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts b/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts index 42aed3507f..80089e9471 100644 --- a/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts @@ -5,8 +5,7 @@ export const DEFAULT_EXPLORER_URLS: Readonly<{ [key in NetworkId]?: string }> = [SupportedNetworkId.Iota]: 'https://explorer.iota.org', [SupportedNetworkId.Shimmer]: 'https://explorer.shimmer.network', [SupportedNetworkId.Testnet]: 'https://explorer.shimmer.network', - [SupportedNetworkId.IotaEvm]: - 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-4307059d77fecb4adb7f81099c9404995ef9f4a617496ee0e1fb7cb0eb46c0ae', + [SupportedNetworkId.IotaEvm]: 'https://explorer.evm.iota.org', [SupportedNetworkId.Ethereum]: 'https://eth.blockscout.com', [SupportedNetworkId.ShimmerEvm]: 'https://explorer.evm.shimmer.network', [SupportedNetworkId.TestnetEvm]: 'https://explorer.evm.testnet.shimmer.network', From cc43b3df71ff49b24504f57c1e8cbc4a5f30490c Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Sun, 5 May 2024 21:51:33 +0100 Subject: [PATCH 19/25] add evm network coin type --- .../src/lib/core/network/constants/default-coin-type.constant.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts b/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts index 9a1fe25891..dafaadd30e 100644 --- a/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts @@ -10,6 +10,7 @@ export const DEFAULT_COIN_TYPE: Readonly<{ [id in NetworkId]: number }> = { [SupportedNetworkId.Iota]: IOTA_COIN_TYPE, [SupportedNetworkId.Shimmer]: SHIMMER_COIN_TYPE, [SupportedNetworkId.Testnet]: TEST_COIN_TYPE, + [SupportedNetworkId.IotaEvm]: ETHEREUM_COIN_TYPE, [SupportedNetworkId.ShimmerEvm]: ETHEREUM_COIN_TYPE, [SupportedNetworkId.TestnetEvm]: ETHEREUM_COIN_TYPE, [SupportedNetworkId.Ethereum]: ETHEREUM_COIN_TYPE, From 13fed9d3151602951426ac7661caaa684dc9b24d Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Sun, 5 May 2024 22:08:17 +0100 Subject: [PATCH 20/25] fix evm icon colour --- packages/shared/src/components/avatars/NetworkAvatar.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/src/components/avatars/NetworkAvatar.svelte b/packages/shared/src/components/avatars/NetworkAvatar.svelte index 0b1e7448bc..a490e99c9d 100644 --- a/packages/shared/src/components/avatars/NetworkAvatar.svelte +++ b/packages/shared/src/components/avatars/NetworkAvatar.svelte @@ -22,7 +22,7 @@ [SupportedNetworkId.Iota]: '#FFFFFF', [SupportedNetworkId.Shimmer]: 'shimmer', [SupportedNetworkId.Testnet]: 'text-secondary', - [SupportedNetworkId.IotaEvm]: '#000000', + [SupportedNetworkId.IotaEvm]: '#FFFFFF', [SupportedNetworkId.ShimmerEvm]: 'text-invert', [SupportedNetworkId.TestnetEvm]: 'shimmer-background', } From cdd850e5dbeaa55da530a30e7e91d2f727718ef4 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Sun, 5 May 2024 22:09:07 +0100 Subject: [PATCH 21/25] fix: default evm constants --- .../core/network/constants/default-base-token.constant.ts | 1 + .../core/network/constants/default-coin-type.constant.ts | 2 +- .../default-isc-chains-configurations.constant.ts | 7 ++++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts b/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts index 535dcb5a26..949647c3fb 100644 --- a/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts @@ -35,6 +35,7 @@ export const DEFAULT_BASE_TOKEN: Readonly<{ [id in NetworkId]?: IBaseToken }> = [SupportedNetworkId.Iota]: IOTA_BASE_TOKEN, [SupportedNetworkId.Shimmer]: SHIMMER_BASE_TOKEN, [SupportedNetworkId.Testnet]: SHIMMER_BASE_TOKEN, + [SupportedNetworkId.IotaEvm]: IOTA_BASE_TOKEN, [SupportedNetworkId.ShimmerEvm]: SHIMMER_BASE_TOKEN, [SupportedNetworkId.TestnetEvm]: SHIMMER_BASE_TOKEN, [SupportedNetworkId.Ethereum]: EVM_BASE_TOKEN, diff --git a/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts b/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts index dafaadd30e..4e99839e71 100644 --- a/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts @@ -6,7 +6,7 @@ export const SHIMMER_COIN_TYPE = 4219 export const TEST_COIN_TYPE = 1 export const ETHEREUM_COIN_TYPE = 60 -export const DEFAULT_COIN_TYPE: Readonly<{ [id in NetworkId]: number }> = { +export const DEFAULT_COIN_TYPE: Readonly<{ [key in NetworkId]: number }> = { [SupportedNetworkId.Iota]: IOTA_COIN_TYPE, [SupportedNetworkId.Shimmer]: SHIMMER_COIN_TYPE, [SupportedNetworkId.Testnet]: TEST_COIN_TYPE, diff --git a/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts b/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts index 71c7218c18..0e3bdf379e 100644 --- a/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts @@ -1,7 +1,7 @@ import { NetworkType, NetworkNamespace, ChainId } from '../enums' import { IIscChainConfiguration } from '../interfaces' import { StardustNetworkId } from '../types' -import { SHIMMER_BASE_TOKEN } from './default-base-token.constant' +import { DEFAULT_BASE_TOKEN } from './default-base-token.constant' import { DEFAULT_COIN_TYPE } from './default-coin-type.constant' import { SupportedIscNetworkId, SupportedNetworkId, SupportedStardustNetworkId } from './supported-network-id.constant' @@ -12,6 +12,7 @@ export const DEFAULT_ISC_CHAINS_CONFIGURATIONS: Readonly<{ [id in StardustNetwor name: 'IOTA EVM', chainId: ChainId.IotaEvm, namespace: NetworkNamespace.Evm, + baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.IotaEvm], coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.IotaEvm], aliasAddress: 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', @@ -28,7 +29,7 @@ export const DEFAULT_ISC_CHAINS_CONFIGURATIONS: Readonly<{ [id in StardustNetwor name: 'Shimmer EVM', chainId: ChainId.ShimmerEvm, namespace: NetworkNamespace.Evm, - baseToken: SHIMMER_BASE_TOKEN, + baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.ShimmerEVM], coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.ShimmerEvm] ?? 0, aliasAddress: 'smr1prxvwqvwf7nru5q5xvh5thwg54zsm2y4wfnk6yk56hj3exxkg92mx20wl3s', rpcEndpoint: 'https://json-rpc.evm.shimmer.network/', @@ -41,7 +42,7 @@ export const DEFAULT_ISC_CHAINS_CONFIGURATIONS: Readonly<{ [id in StardustNetwor name: 'Testnet EVM', chainId: ChainId.TestnetEvm, namespace: NetworkNamespace.Evm, - baseToken: SHIMMER_BASE_TOKEN, + baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.TestnetEvm], coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.TestnetEvm] ?? 0, aliasAddress: 'rms1ppp00k5mmd2m8my8ukkp58nd3rskw6rx8l09aj35984k74uuc5u2cywn3ex', rpcEndpoint: 'https://json-rpc.evm.testnet.shimmer.network/', From cffb38e2b35991729c11dc42ce9eea7a369cd7f2 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Mon, 6 May 2024 10:31:36 +0100 Subject: [PATCH 22/25] chore: feature flag default isc chains --- .../desktop/features/onboarding.features.ts | 12 +++ .../constants/default-base-token.constant.ts | 2 +- ...ault-isc-chains-configurations.constant.ts | 93 ++++++++++--------- ...boarding-features-for-network.interface.ts | 1 + 4 files changed, 64 insertions(+), 44 deletions(-) diff --git a/packages/desktop/features/onboarding.features.ts b/packages/desktop/features/onboarding.features.ts index d7bc4104e2..41d31406ef 100644 --- a/packages/desktop/features/onboarding.features.ts +++ b/packages/desktop/features/onboarding.features.ts @@ -41,6 +41,9 @@ const onboardingFeaturesForIota: IOnboardingFeaturesForNetwork = { enabled: false, }, }, + defaultIscChains: { + enabled: false, + }, } const onboardingFeaturesForShimmer: IOnboardingFeaturesForNetwork = { @@ -82,6 +85,9 @@ const onboardingFeaturesForShimmer: IOnboardingFeaturesForNetwork = { enabled: true, }, }, + defaultIscChains: { + enabled: true, + }, } const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = { @@ -123,6 +129,9 @@ const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = { enabled: true, }, }, + defaultIscChains: { + enabled: true, + }, } const onboardingFeaturesForCustom: IOnboardingFeaturesForNetwork = { @@ -164,6 +173,9 @@ const onboardingFeaturesForCustom: IOnboardingFeaturesForNetwork = { enabled: true, }, }, + defaultIscChains: { + enabled: false, + }, } const onboardingFeatures: OnboardingFeatures = { diff --git a/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts b/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts index 949647c3fb..b138e035ed 100644 --- a/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts @@ -31,7 +31,7 @@ export const EVM_BASE_TOKEN: IBaseToken = { decimals: 18, } -export const DEFAULT_BASE_TOKEN: Readonly<{ [id in NetworkId]?: IBaseToken }> = { +export const DEFAULT_BASE_TOKEN: Readonly<{ [id in NetworkId]: IBaseToken }> = { [SupportedNetworkId.Iota]: IOTA_BASE_TOKEN, [SupportedNetworkId.Shimmer]: SHIMMER_BASE_TOKEN, [SupportedNetworkId.Testnet]: SHIMMER_BASE_TOKEN, diff --git a/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts b/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts index 0e3bdf379e..f37c100e04 100644 --- a/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts @@ -1,3 +1,4 @@ +import features from '@features/features' import { NetworkType, NetworkNamespace, ChainId } from '../enums' import { IIscChainConfiguration } from '../interfaces' import { StardustNetworkId } from '../types' @@ -6,47 +7,53 @@ import { DEFAULT_COIN_TYPE } from './default-coin-type.constant' import { SupportedIscNetworkId, SupportedNetworkId, SupportedStardustNetworkId } from './supported-network-id.constant' export const DEFAULT_ISC_CHAINS_CONFIGURATIONS: Readonly<{ [id in StardustNetworkId]?: IIscChainConfiguration }> = { - [SupportedStardustNetworkId.Iota]: { - id: SupportedIscNetworkId.IotaEvm, - type: NetworkType.Isc, - name: 'IOTA EVM', - chainId: ChainId.IotaEvm, - namespace: NetworkNamespace.Evm, - baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.IotaEvm], - coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.IotaEvm], - aliasAddress: - 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', - rpcEndpoint: - 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', - apiEndpoint: - 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', - explorerUrl: - 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', - } as IIscChainConfiguration, - [SupportedStardustNetworkId.Shimmer]: { - id: SupportedIscNetworkId.ShimmerEvm, - type: NetworkType.Isc, - name: 'Shimmer EVM', - chainId: ChainId.ShimmerEvm, - namespace: NetworkNamespace.Evm, - baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.ShimmerEVM], - coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.ShimmerEvm] ?? 0, - aliasAddress: 'smr1prxvwqvwf7nru5q5xvh5thwg54zsm2y4wfnk6yk56hj3exxkg92mx20wl3s', - rpcEndpoint: 'https://json-rpc.evm.shimmer.network/', - apiEndpoint: 'https://api.evm.shimmer.network/', - explorerUrl: 'https://explorer.evm.shimmer.network/', - }, - [SupportedStardustNetworkId.Testnet]: { - id: SupportedIscNetworkId.TestnetEvm, - type: NetworkType.Isc, - name: 'Testnet EVM', - chainId: ChainId.TestnetEvm, - namespace: NetworkNamespace.Evm, - baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.TestnetEvm], - coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.TestnetEvm] ?? 0, - aliasAddress: 'rms1ppp00k5mmd2m8my8ukkp58nd3rskw6rx8l09aj35984k74uuc5u2cywn3ex', - rpcEndpoint: 'https://json-rpc.evm.testnet.shimmer.network/', - apiEndpoint: 'https://api.evm.testnet.shimmer.network/', - explorerUrl: 'https://explorer.evm.testnet.shimmer.network/', - }, + ...(features.onboarding.iota?.defaultIscChains.enabled && { + [SupportedStardustNetworkId.Iota]: { + id: SupportedIscNetworkId.IotaEvm, + type: NetworkType.Isc, + name: 'IOTA EVM', + chainId: ChainId.IotaEvm, + namespace: NetworkNamespace.Evm, + baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.IotaEvm], + coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.IotaEvm], + aliasAddress: + 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', + rpcEndpoint: + 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', + apiEndpoint: + 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', + explorerUrl: + 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', + }, + }), + ...(features.onboarding.shimmer?.defaultIscChains.enabled && { + [SupportedStardustNetworkId.Shimmer]: { + id: SupportedIscNetworkId.ShimmerEvm, + type: NetworkType.Isc, + name: 'Shimmer EVM', + chainId: ChainId.ShimmerEvm, + namespace: NetworkNamespace.Evm, + baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.ShimmerEVM], + coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.ShimmerEvm] ?? 0, + aliasAddress: 'smr1prxvwqvwf7nru5q5xvh5thwg54zsm2y4wfnk6yk56hj3exxkg92mx20wl3s', + rpcEndpoint: 'https://json-rpc.evm.shimmer.network/', + apiEndpoint: 'https://api.evm.shimmer.network/', + explorerUrl: 'https://explorer.evm.shimmer.network/', + }, + }), + ...(features.onboarding.testnet?.defaultIscChains.enabled && { + [SupportedStardustNetworkId.Testnet]: { + id: SupportedIscNetworkId.TestnetEvm, + type: NetworkType.Isc, + name: 'Testnet EVM', + chainId: ChainId.TestnetEvm, + namespace: NetworkNamespace.Evm, + baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.TestnetEvm], + coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.TestnetEvm] ?? 0, + aliasAddress: 'rms1ppp00k5mmd2m8my8ukkp58nd3rskw6rx8l09aj35984k74uuc5u2cywn3ex', + rpcEndpoint: 'https://json-rpc.evm.testnet.shimmer.network/', + apiEndpoint: 'https://api.evm.testnet.shimmer.network/', + explorerUrl: 'https://explorer.evm.testnet.shimmer.network/', + }, + }), } diff --git a/packages/shared/src/lib/features/interfaces/onboarding-features-for-network.interface.ts b/packages/shared/src/lib/features/interfaces/onboarding-features-for-network.interface.ts index ae3c63f411..6fc84fc93c 100644 --- a/packages/shared/src/lib/features/interfaces/onboarding-features-for-network.interface.ts +++ b/packages/shared/src/lib/features/interfaces/onboarding-features-for-network.interface.ts @@ -17,4 +17,5 @@ export interface IOnboardingFeaturesForNetwork extends IFeatureFlag { strongholdBackup: IFeatureFlag ledgerBackup: IFeatureFlag } + defaultIscChains: IFeatureFlag } From f5f18d5adf36dd9f99cd8e6b9d7589e6e2c33a34 Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Mon, 6 May 2024 11:52:14 +0200 Subject: [PATCH 23/25] cleanup buffer calculation --- .../components/EvmTransactionSummary.svelte | 11 +++++++++-- .../utils/getL2ToL1StorageDepositBuffer.ts | 17 ++++++++++------- .../lib/core/network/stores/networks.store.ts | 8 +++++++- .../send/createEvmToStardustTransaction.ts | 8 ++++++-- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte b/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte index 17cd81fc44..b15e9c1a0d 100644 --- a/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte +++ b/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte @@ -10,6 +10,7 @@ import { TransactionAssetSection } from '@ui' import EvmTransactionDetails from './EvmTransactionDetails.svelte' import { handleError } from '@core/error/handlers' + import { StardustNetworkId } from '@core/network' export let transaction: EvmTransactionData export let sendFlowParameters: SendFlowParameters @@ -36,7 +37,10 @@ destinationNetworkId && destinationNetworkId !== _sendFlowParameters?.tokenTransfer?.token.networkId ) { - return getL2ToL1StorageDepositBuffer(SendFlowType.TokenUnwrap, destinationNetworkId) + return getL2ToL1StorageDepositBuffer( + SendFlowType.TokenUnwrap, + destinationNetworkId as StardustNetworkId + ) } } else if (type === SendFlowType.NftTransfer) { if ( @@ -44,7 +48,10 @@ destinationNetworkId !== _sendFlowParameters.nft?.networkId && isIrc27Nft(_sendFlowParameters.nft) ) { - const buffer = getL2ToL1StorageDepositBuffer(SendFlowType.NftUnwrap, destinationNetworkId) + const buffer = getL2ToL1StorageDepositBuffer( + SendFlowType.NftUnwrap, + destinationNetworkId as StardustNetworkId + ) return (_sendFlowParameters.nft?.storageDeposit ?? BigInt(0)) + buffer } } diff --git a/packages/shared/src/lib/core/layer-2/utils/getL2ToL1StorageDepositBuffer.ts b/packages/shared/src/lib/core/layer-2/utils/getL2ToL1StorageDepositBuffer.ts index cc58ad95e6..6da08e294c 100644 --- a/packages/shared/src/lib/core/layer-2/utils/getL2ToL1StorageDepositBuffer.ts +++ b/packages/shared/src/lib/core/layer-2/utils/getL2ToL1StorageDepositBuffer.ts @@ -1,8 +1,6 @@ -import { nodeInfo } from '@core/network' +import { StardustNetworkId, getStardustNetwork } from '@core/network' import { DEFAULT_PROTOCOL } from '@core/network/constants' -import { NetworkId } from '@core/network/types' import { SendFlowType } from '@core/wallet/enums' -import { get } from 'svelte/store' const L2_TO_L1_STORAGE_DEPOSIT_BUFFER_BYTES: { [key in UnwrapSendFlow]: bigint } = { [SendFlowType.TokenUnwrap]: BigInt(565), @@ -11,13 +9,18 @@ const L2_TO_L1_STORAGE_DEPOSIT_BUFFER_BYTES: { [key in UnwrapSendFlow]: bigint } type UnwrapSendFlow = SendFlowType.TokenUnwrap | SendFlowType.NftUnwrap -export function getL2ToL1StorageDepositBuffer(type: UnwrapSendFlow, network: NetworkId): bigint { - const actualVByteCost = get(nodeInfo)?.protocol.rentStructure.vByteCost - let expectedVByteCost = DEFAULT_PROTOCOL[network]?.rentStructure.vByteCost +export function getL2ToL1StorageDepositBuffer(type: UnwrapSendFlow, networkId: StardustNetworkId): bigint { + const network = getStardustNetwork(networkId) + if (!network) { + return BigInt(0) + } + + const actualVByteCost = network.protocol.rentStructure.vByteCost + let expectedVByteCost = DEFAULT_PROTOCOL[networkId]?.rentStructure.vByteCost // TODO: Validate byte cost returned by node if (!expectedVByteCost && !actualVByteCost) { - throw new Error(`Virtual byte cost for ${network} is undefined!`) + throw new Error(`Virtual byte cost for ${networkId} is undefined!`) // } else if (!actualVByteCost) { // throw new Error('Node does not return virtual byte cost') } else if (!expectedVByteCost) { diff --git a/packages/shared/src/lib/core/network/stores/networks.store.ts b/packages/shared/src/lib/core/network/stores/networks.store.ts index 0b9b0d925c..d9fe024537 100644 --- a/packages/shared/src/lib/core/network/stores/networks.store.ts +++ b/packages/shared/src/lib/core/network/stores/networks.store.ts @@ -5,7 +5,7 @@ import features from '@features/features' import { IscChain, EvmNetwork, StardustNetwork } from '../classes' import { IEvmNetwork, IIscChain, IStardustNetwork } from '../interfaces' -import { EvmNetworkId, Network, NetworkId } from '../types' +import { EvmNetworkId, Network, NetworkId, StardustNetworkId } from '../types' import { NetworkType, NetworkNamespace } from '../enums' export const networks: Writable = writable([]) @@ -66,6 +66,12 @@ export function getL1Network(): IStardustNetwork { return l1Network } +export function getStardustNetwork(networkId: StardustNetworkId): IStardustNetwork | undefined { + return get(networks)?.find( + (network) => network.namespace === NetworkNamespace.Stardust && network.id === networkId + ) as IStardustNetwork +} + export function getEvmNetworks(): IEvmNetwork[] { return (get(networks)?.filter((network) => network.namespace === NetworkNamespace.Evm) as IEvmNetwork[]) ?? [] } diff --git a/packages/shared/src/lib/core/wallet/actions/send/createEvmToStardustTransaction.ts b/packages/shared/src/lib/core/wallet/actions/send/createEvmToStardustTransaction.ts index 9cd74fc4ad..a05bd5b842 100644 --- a/packages/shared/src/lib/core/wallet/actions/send/createEvmToStardustTransaction.ts +++ b/packages/shared/src/lib/core/wallet/actions/send/createEvmToStardustTransaction.ts @@ -15,6 +15,7 @@ import { TokenStandard } from '@core/token/enums' import { IIrc27Nft } from '@core/nfts' import { getTokenBalance } from '@core/token/actions' import { IError } from '@core/error' +import { StardustNetworkId } from '@core/network' export async function createEvmToStardustTransaction( sendFlowParameters: SendFlowParameters, @@ -38,7 +39,10 @@ export async function createEvmToStardustTransaction( const { token, amount } = getAmountAndTokenFromSendFlowParameters(sendFlowParameters) const isBaseCoin = token?.standard === TokenStandard.BaseToken const assetType = isBaseCoin ? AssetType.BaseCoin : AssetType.Token - storageDepositRequired = getL2ToL1StorageDepositBuffer(SendFlowType.TokenUnwrap, destinationNetworkId) + storageDepositRequired = getL2ToL1StorageDepositBuffer( + SendFlowType.TokenUnwrap, + destinationNetworkId as StardustNetworkId + ) transferredAsset = token && amount ? { type: assetType, token, amount } : undefined if (token?.standard === TokenStandard.BaseToken && amount) { const availableBalance = getTokenBalance(token.id, evmNetwork.id)?.available ?? BigInt(0) @@ -48,7 +52,7 @@ export async function createEvmToStardustTransaction( const nft = sendFlowParameters.nft as IIrc27Nft storageDepositRequired = (nft?.storageDeposit ?? BigInt(0)) + - getL2ToL1StorageDepositBuffer(SendFlowType.NftUnwrap, destinationNetworkId) + getL2ToL1StorageDepositBuffer(SendFlowType.NftUnwrap, destinationNetworkId as StardustNetworkId) transferredAsset = nft ? { type: AssetType.Nft, nft } : undefined } From a97f8d723831940a8a3f8d467b9f778183b43a03 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Mon, 6 May 2024 16:37:51 +0100 Subject: [PATCH 24/25] fix: tests --- ...ault-isc-chains-configurations.constant.ts | 101 ++++++++++-------- .../wallet/tests/getOutputParameters.test.ts | 22 +++- .../types/onboarding-features.type.ts | 2 +- .../shared/src/lib/features/utils/index.ts | 1 + .../lib/features/utils/isFeatureEnabled.ts | 19 ++++ 5 files changed, 92 insertions(+), 53 deletions(-) create mode 100644 packages/shared/src/lib/features/utils/index.ts create mode 100644 packages/shared/src/lib/features/utils/isFeatureEnabled.ts diff --git a/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts b/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts index f37c100e04..513b7f9d33 100644 --- a/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts @@ -1,59 +1,66 @@ -import features from '@features/features' import { NetworkType, NetworkNamespace, ChainId } from '../enums' import { IIscChainConfiguration } from '../interfaces' import { StardustNetworkId } from '../types' import { DEFAULT_BASE_TOKEN } from './default-base-token.constant' import { DEFAULT_COIN_TYPE } from './default-coin-type.constant' import { SupportedIscNetworkId, SupportedNetworkId, SupportedStardustNetworkId } from './supported-network-id.constant' +import { isFeatureEnabled } from '@lib/features/utils' + +const IOTA_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { + id: SupportedIscNetworkId.IotaEvm, + type: NetworkType.Isc, + name: 'IOTA EVM', + chainId: ChainId.IotaEvm, + namespace: NetworkNamespace.Evm, + baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.IotaEvm], + coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.IotaEvm], + aliasAddress: + 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', + rpcEndpoint: + 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', + apiEndpoint: + 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', + explorerUrl: + 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', +} + +const SHIMMER_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { + id: SupportedIscNetworkId.ShimmerEvm, + type: NetworkType.Isc, + name: 'Shimmer EVM', + chainId: ChainId.ShimmerEvm, + namespace: NetworkNamespace.Evm, + baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.ShimmerEVM], + coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.ShimmerEvm] ?? 0, + aliasAddress: 'smr1prxvwqvwf7nru5q5xvh5thwg54zsm2y4wfnk6yk56hj3exxkg92mx20wl3s', + rpcEndpoint: 'https://json-rpc.evm.shimmer.network/', + apiEndpoint: 'https://api.evm.shimmer.network/', + explorerUrl: 'https://explorer.evm.shimmer.network/', +} + +// exported as used in tests +export const TESTNET_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { + id: SupportedIscNetworkId.TestnetEvm, + type: NetworkType.Isc, + name: 'Testnet EVM', + chainId: ChainId.TestnetEvm, + namespace: NetworkNamespace.Evm, + baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.TestnetEvm], + coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.TestnetEvm] ?? 0, + aliasAddress: 'rms1ppp00k5mmd2m8my8ukkp58nd3rskw6rx8l09aj35984k74uuc5u2cywn3ex', + rpcEndpoint: 'https://json-rpc.evm.testnet.shimmer.network/', + apiEndpoint: 'https://api.evm.testnet.shimmer.network/', + explorerUrl: 'https://explorer.evm.testnet.shimmer.network/', +} export const DEFAULT_ISC_CHAINS_CONFIGURATIONS: Readonly<{ [id in StardustNetworkId]?: IIscChainConfiguration }> = { - ...(features.onboarding.iota?.defaultIscChains.enabled && { - [SupportedStardustNetworkId.Iota]: { - id: SupportedIscNetworkId.IotaEvm, - type: NetworkType.Isc, - name: 'IOTA EVM', - chainId: ChainId.IotaEvm, - namespace: NetworkNamespace.Evm, - baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.IotaEvm], - coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.IotaEvm], - aliasAddress: - 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', - rpcEndpoint: - 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', - apiEndpoint: - 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', - explorerUrl: - 'https://github.com/bloomwalletio/bloom-private/pull/17/files#diff-2e95221dbfb375be5e97b45bad40479c2b3f9a70efa14e66caa1b7fe37df8296', - }, + ...(isFeatureEnabled('onboarding.iota.defaultIscChains') && { + [SupportedStardustNetworkId.Iota]: IOTA_EVM_CHAIN_CONFIGURATION, }), - ...(features.onboarding.shimmer?.defaultIscChains.enabled && { - [SupportedStardustNetworkId.Shimmer]: { - id: SupportedIscNetworkId.ShimmerEvm, - type: NetworkType.Isc, - name: 'Shimmer EVM', - chainId: ChainId.ShimmerEvm, - namespace: NetworkNamespace.Evm, - baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.ShimmerEVM], - coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.ShimmerEvm] ?? 0, - aliasAddress: 'smr1prxvwqvwf7nru5q5xvh5thwg54zsm2y4wfnk6yk56hj3exxkg92mx20wl3s', - rpcEndpoint: 'https://json-rpc.evm.shimmer.network/', - apiEndpoint: 'https://api.evm.shimmer.network/', - explorerUrl: 'https://explorer.evm.shimmer.network/', - }, + ...(isFeatureEnabled('onboarding.shimmer.defaultIscChains') && { + [SupportedStardustNetworkId.Shimmer]: SHIMMER_EVM_CHAIN_CONFIGURATION, }), - ...(features.onboarding.testnet?.defaultIscChains.enabled && { - [SupportedStardustNetworkId.Testnet]: { - id: SupportedIscNetworkId.TestnetEvm, - type: NetworkType.Isc, - name: 'Testnet EVM', - chainId: ChainId.TestnetEvm, - namespace: NetworkNamespace.Evm, - baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.TestnetEvm], - coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.TestnetEvm] ?? 0, - aliasAddress: 'rms1ppp00k5mmd2m8my8ukkp58nd3rskw6rx8l09aj35984k74uuc5u2cywn3ex', - rpcEndpoint: 'https://json-rpc.evm.testnet.shimmer.network/', - apiEndpoint: 'https://api.evm.testnet.shimmer.network/', - explorerUrl: 'https://explorer.evm.testnet.shimmer.network/', - }, + ...(isFeatureEnabled('onboarding.testnet.defaultIscChains') && { + [SupportedStardustNetworkId.Testnet]: TESTNET_EVM_CHAIN_CONFIGURATION, }), } diff --git a/packages/shared/src/lib/core/wallet/tests/getOutputParameters.test.ts b/packages/shared/src/lib/core/wallet/tests/getOutputParameters.test.ts index 4d701d3538..fcfe5ffefd 100644 --- a/packages/shared/src/lib/core/wallet/tests/getOutputParameters.test.ts +++ b/packages/shared/src/lib/core/wallet/tests/getOutputParameters.test.ts @@ -1,5 +1,5 @@ import { FALLBACK_ESTIMATED_GAS } from '@core/layer-2/constants' -import { DEFAULT_ISC_CHAINS_CONFIGURATIONS, SupportedNetworkId } from '@core/network/constants' +import { TESTNET_EVM_CHAIN_CONFIGURATION, SupportedNetworkId } from '@core/network/constants' import { getOutputParameters } from '../utils' import { ReturnStrategy, SubjectType } from '../enums' import { IToken, IPersistedToken } from '@core/token/interfaces' @@ -32,7 +32,19 @@ const nativeTokenAsset: IToken = { verification: { verified: true, status: VerifiedStatus.SelfVerified }, } -const destinationNetwork = DEFAULT_ISC_CHAINS_CONFIGURATIONS[SupportedNetworkId.Testnet] +const destinationNetwork = { + ...TESTNET_EVM_CHAIN_CONFIGURATION, + getMetadata() { + return { + gasFeePolicy: { + gasPerToken: { + a: 1, + b: 1, + }, + }, + } + }, +} const nftId = '0xcd9430ff870a22f81f92428e5c06975fa3ec1a993331aa3db9fb2298e931ade1' const surplus = '50000' @@ -227,7 +239,7 @@ describe('File: getOutputParameters.ts', () => { ...baseTransaction, expirationDate, destinationNetworkId: destinationNetwork.id, - gasFee, + gasFee: BigInt(gasFee), } const output = getOutputParameters(sendFlowParameters, senderAddress) const expectedOutput = { @@ -259,7 +271,7 @@ describe('File: getOutputParameters.ts', () => { rawAmount: BigInt(amount), }, destinationNetworkId: destinationNetwork.id, - gasFee, + gasFee: BigInt(gasFee), } const output = getOutputParameters(sendFlowParameters, senderAddress) @@ -291,7 +303,7 @@ describe('File: getOutputParameters.ts', () => { recipient: baseTransaction.recipient, nft: testNft, destinationNetworkId: destinationNetwork.id, - gasFee, + gasFee: BigInt(gasFee), } const output = getOutputParameters(sendFlowParameters, senderAddress) diff --git a/packages/shared/src/lib/features/types/onboarding-features.type.ts b/packages/shared/src/lib/features/types/onboarding-features.type.ts index 3f35ce59e7..17efeb4a06 100644 --- a/packages/shared/src/lib/features/types/onboarding-features.type.ts +++ b/packages/shared/src/lib/features/types/onboarding-features.type.ts @@ -2,7 +2,7 @@ import { OnboardingNetworkType } from '@contexts/onboarding/enums' import { IFeatureFlag, IOnboardingFeaturesForNetwork } from '../interfaces' export type OnboardingFeatures = IFeatureFlag & { - [key in OnboardingNetworkType]?: IOnboardingFeaturesForNetwork & IFeatureFlag + [key in OnboardingNetworkType]: IOnboardingFeaturesForNetwork & IFeatureFlag } & { importFromThirdParty: IFeatureFlag strongholdVersionCheck: IFeatureFlag diff --git a/packages/shared/src/lib/features/utils/index.ts b/packages/shared/src/lib/features/utils/index.ts new file mode 100644 index 0000000000..29563dad5d --- /dev/null +++ b/packages/shared/src/lib/features/utils/index.ts @@ -0,0 +1 @@ +export * from './isFeatureEnabled' diff --git a/packages/shared/src/lib/features/utils/isFeatureEnabled.ts b/packages/shared/src/lib/features/utils/isFeatureEnabled.ts new file mode 100644 index 0000000000..400afdaffa --- /dev/null +++ b/packages/shared/src/lib/features/utils/isFeatureEnabled.ts @@ -0,0 +1,19 @@ +import featuresObject from '@features/features' + +export function isFeatureEnabled(featureString: string, recursive: boolean = true): boolean { + const featurePathToCheck = featureString.split('.') + let previousFeatures = featuresObject + for (let i = 0; i < featurePathToCheck.length; i++) { + const currentFeature = previousFeatures[featurePathToCheck[i]] + + if (i === featurePathToCheck.length - 1 && currentFeature?.enabled) { + return true + } + + if (recursive && !currentFeature?.enabled) { + return false + } + previousFeatures = currentFeature + } + return false +} From 427a1f7ec88a3ad5ba8ef8a966af98ec9130080f Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Mon, 6 May 2024 17:57:40 +0200 Subject: [PATCH 25/25] fix tests --- .../core/wallet/tests/getOutputParameters.test.ts | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/packages/shared/src/lib/core/wallet/tests/getOutputParameters.test.ts b/packages/shared/src/lib/core/wallet/tests/getOutputParameters.test.ts index fcfe5ffefd..3124ad73a5 100644 --- a/packages/shared/src/lib/core/wallet/tests/getOutputParameters.test.ts +++ b/packages/shared/src/lib/core/wallet/tests/getOutputParameters.test.ts @@ -1,5 +1,6 @@ import { FALLBACK_ESTIMATED_GAS } from '@core/layer-2/constants' import { TESTNET_EVM_CHAIN_CONFIGURATION, SupportedNetworkId } from '@core/network/constants' +import { IscChain } from '@core/network/classes' import { getOutputParameters } from '../utils' import { ReturnStrategy, SubjectType } from '../enums' import { IToken, IPersistedToken } from '@core/token/interfaces' @@ -32,19 +33,7 @@ const nativeTokenAsset: IToken = { verification: { verified: true, status: VerifiedStatus.SelfVerified }, } -const destinationNetwork = { - ...TESTNET_EVM_CHAIN_CONFIGURATION, - getMetadata() { - return { - gasFeePolicy: { - gasPerToken: { - a: 1, - b: 1, - }, - }, - } - }, -} +const destinationNetwork = new IscChain(TESTNET_EVM_CHAIN_CONFIGURATION) const nftId = '0xcd9430ff870a22f81f92428e5c06975fa3ec1a993331aa3db9fb2298e931ade1' const surplus = '50000'