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

v4 fix: several issues OK-27771 #4586

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 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
Loading