From 2158a52295a43b956b290032f1241b37d7469393 Mon Sep 17 00:00:00 2001 From: weatherstar Date: Wed, 15 May 2024 10:26:43 +0800 Subject: [PATCH] v4 fix: several issues OK-27771 (#4586) * fix: account balance * fix: account index symbol * fix: base&arb testnet max send error --- .../engine/src/vaults/impl/ada/settings.ts | 2 +- .../engine/src/vaults/impl/dynex/Vault.ts | 8 +- .../engine/src/vaults/impl/dynex/settings.ts | 2 +- packages/engine/src/vaults/impl/evm/Vault.ts | 77 ++++++++++++------- 4 files changed, 56 insertions(+), 33 deletions(-) diff --git a/packages/engine/src/vaults/impl/ada/settings.ts b/packages/engine/src/vaults/impl/ada/settings.ts index fe233311998..db717ad653a 100644 --- a/packages/engine/src/vaults/impl/ada/settings.ts +++ b/packages/engine/src/vaults/impl/ada/settings.ts @@ -29,7 +29,7 @@ const settings: IVaultSettings = Object.freeze({ template: `m/1852'/${COINTYPE_ADA}'/${INDEX_PLACEHOLDER}'/0/0`, coinType: COINTYPE_ADA, label: 'Shelley', - subDesc: `m/1852'/${COINTYPE_ADA}'/x'/0/0`, + subDesc: `m/1852'/${COINTYPE_ADA}'/*'/0/0`, }, }, }); diff --git a/packages/engine/src/vaults/impl/dynex/Vault.ts b/packages/engine/src/vaults/impl/dynex/Vault.ts index d352fdfd6ff..413522a62d1 100644 --- a/packages/engine/src/vaults/impl/dynex/Vault.ts +++ b/packages/engine/src/vaults/impl/dynex/Vault.ts @@ -83,8 +83,12 @@ export default class Vault extends VaultBase { const client = await this.getClient(); const balances: (BigNumber | undefined)[] = []; for (let i = 0; i < requests.length; i += 1) { - const balance = await client.getBalanceOfAddress(requests[i].address); - balances.push(balance); + try { + const balance = await client.getBalanceOfAddress(requests[i].address); + balances.push(balance); + } catch (e) { + balances.push(new BigNumber(0)); + } } return balances; diff --git a/packages/engine/src/vaults/impl/dynex/settings.ts b/packages/engine/src/vaults/impl/dynex/settings.ts index 01639666589..845087e84f6 100644 --- a/packages/engine/src/vaults/impl/dynex/settings.ts +++ b/packages/engine/src/vaults/impl/dynex/settings.ts @@ -34,7 +34,7 @@ const settings: IVaultSettings = Object.freeze({ template: `m/44'/${COINTYPE_DYNEX}'/0'/0'/${INDEX_PLACEHOLDER}'`, coinType: COINTYPE_DYNEX, label: 'Default', - subDesc: `m/44'/${COINTYPE_DYNEX}'/0'/0'/x'`, + subDesc: `m/44'/${COINTYPE_DYNEX}'/0'/0'/*'`, }, }, }); diff --git a/packages/engine/src/vaults/impl/evm/Vault.ts b/packages/engine/src/vaults/impl/evm/Vault.ts index 289260ea34f..1ef050e9008 100644 --- a/packages/engine/src/vaults/impl/evm/Vault.ts +++ b/packages/engine/src/vaults/impl/evm/Vault.ts @@ -140,10 +140,17 @@ import type { import type { IRpcTxEvm } from './types'; import type { IJsonRpcRequest } from '@onekeyfe/cross-inpage-provider-types'; +const BASE_SEPOLIA = 'evm--84532'; +const ARB_SEPOLIA = 'evm--421614'; + const EVM_L2_NETWORKS_REQUIRE_L1_FEE: string[] = [ OnekeyNetwork.optimism, OnekeyNetwork.toptimism, OnekeyNetwork.base, + OnekeyNetwork.arbitrum, + OnekeyNetwork.tarbitrum, + BASE_SEPOLIA, + ARB_SEPOLIA, ]; const ERC721 = ERC721MetadataArtifact.abi; @@ -1273,37 +1280,49 @@ export default class Vault extends VaultBase { // For L2 networks with L1 fee. let baseFeeValue = '0'; if (EVM_L2_NETWORKS_REQUIRE_L1_FEE.includes(this.networkId)) { - // Optimism & Optimism Kovan - // call gasL1Fee(bytes) of GasPriceOracle at 0x420000000000000000000000000000000000000F - const txData = ethers.utils.serializeTransaction({ - value: encodedTx.value, - data: encodedTx.data, - gasLimit: `0x${(unsignedTx?.feeLimit ?? new BigNumber('0')).toString( - 16, - )}`, - to: encodedTx.to, - chainId: 10, // any number other than 0 will lead to fixed length of data - gasPrice: '0xf4240', // 0.001 Gwei - nonce: 1, - }); - - // keccak256(Buffer.from('getL1Fee(bytes)')) => '0x49948e0e...' - const data = `0x49948e0e${defaultAbiCoder - .encode(['bytes'], [txData]) - .slice(2)}`; const client = await this.getJsonRPCClient(); + if ( + this.networkId === OnekeyNetwork.arbitrum || + this.networkId === ARB_SEPOLIA + ) { + // keccak256(Buffer.from('getL1BaseFeeEstimate()')) => '0xf5d6ded7...' + const data = '0xf5d6ded7'; + const l1FeeHex = await client.rpc.call('eth_call', [ + { to: '0x000000000000000000000000000000000000006C', data }, + 'latest', + ]); + + baseFeeValue = new BigNumber(l1FeeHex as string) + .shiftedBy(-network.feeDecimals) + .toFixed(); + } else { + const txData = ethers.utils.serializeTransaction({ + value: encodedTx.value, + data: encodedTx.data, + gasLimit: `0x${(unsignedTx?.feeLimit ?? new BigNumber('0')).toString( + 16, + )}`, + to: encodedTx.to, + chainId: 10, // any number other than 0 will lead to fixed length of data + gasPrice: '0xf4240', // 0.001 Gwei + nonce: 1, + }); - // RPC: eth_call - const l1FeeHex = await client.rpc.call('eth_call', [ - { to: '0x420000000000000000000000000000000000000F', data }, - 'latest', - ]); - // RPC: eth_getBlockByNumber (rpc status check?) - // RPC: eth_getBalance useManageTokensOfAccount/useReloadAccountBalance - // may call multiple times - baseFeeValue = new BigNumber(l1FeeHex as string) - .shiftedBy(-network.feeDecimals) - .toFixed(); + // keccak256(Buffer.from('getL1Fee(bytes)')) => '0x49948e0e...' + const data = `0x49948e0e${defaultAbiCoder + .encode(['bytes'], [txData]) + .slice(2)}`; + + // RPC: eth_call + const l1FeeHex = await client.rpc.call('eth_call', [ + { to: '0x420000000000000000000000000000000000000F', data }, + 'latest', + ]); + + baseFeeValue = new BigNumber(l1FeeHex as string) + .shiftedBy(-network.feeDecimals) + .toFixed(); + } } const eip1559 = Boolean(