Skip to content

Commit

Permalink
v4 fix: several issues OK-27771 (#4586)
Browse files Browse the repository at this point in the history
* fix: account balance

* fix: account index symbol

* fix: base&arb testnet max send error
  • Loading branch information
weatherstar committed May 15, 2024
1 parent 8cb5177 commit 2158a52
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/engine/src/vaults/impl/ada/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
},
},
});
Expand Down
8 changes: 6 additions & 2 deletions packages/engine/src/vaults/impl/dynex/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/src/vaults/impl/dynex/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'/*'`,
},
},
});
Expand Down
77 changes: 48 additions & 29 deletions packages/engine/src/vaults/impl/evm/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 2158a52

Please sign in to comment.