From 4e7071a572c94b1d2af08520528bc817e90490e1 Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:11:03 -0800 Subject: [PATCH 1/3] fix: base max fee --- .../ethereum/libs/transaction/index.ts | 113 +++++++++++------- 1 file changed, 67 insertions(+), 46 deletions(-) diff --git a/packages/extension/src/providers/ethereum/libs/transaction/index.ts b/packages/extension/src/providers/ethereum/libs/transaction/index.ts index a0e740936..8936a04d0 100644 --- a/packages/extension/src/providers/ethereum/libs/transaction/index.ts +++ b/packages/extension/src/providers/ethereum/libs/transaction/index.ts @@ -38,14 +38,13 @@ class Transaction { value: this.tx.value || '0x0', }); } - async getOPfees(): Promise { + async getOPfees( + fTx: LegacyTransaction | FeeMarketEIP1559Transaction, + ): Promise { const OPContract = new this.web3.Contract( OPTIMISM_PRICE_ORACLE_ABI as any, OPTIMISM_PRICE_ORACLE, ); - const fTx = await this.getFinalizedTransaction({ - gasPriceType: GasPriceTypes.ECONOMY, - }); const serializedTx = fTx.serialize(); return OPContract.methods .getL1Fee(bufferToHex(serializedTx)) @@ -87,6 +86,7 @@ class Transaction { maxFeePerGas?: string; gasLimit: string; formattedFeeHistory?: FormattedFeeHistory; + finalizedTransaction: LegacyTransaction | FeeMarketEIP1559Transaction; }> { const latestBlock = await this.web3.getBlock('latest', false); const { isFeeMarketNetwork, feeHistory } = await this.web3 @@ -123,10 +123,20 @@ class Transaction { nonce: this.tx.nonce || (numberToHex(nonce) as `0x${string}`), value: this.tx.value || '0x0', }; + const common = Common.custom({ + chainId: BigInt(this.tx.chainId), + }); + const finalizedTransaction = LegacyTransaction.fromTxData( + legacyTx as FinalizedLegacyEthereumTransaction, + { + common, + }, + ); return { transaction: legacyTx, gasPrice: gasPrice, gasLimit: legacyTx.gasLimit, + finalizedTransaction, }; } else { // Fee market transaction (post EIP1559) @@ -141,7 +151,7 @@ class Transaction { const gasLimit = this.tx.gasLimit || (numberToHex(await this.estimateGas()) as `0x${string}`); - const maxFeePerGas = !options.totalGasPrice + let maxFeePerGas = !options.totalGasPrice ? feeMarket.maxFeePerGas : options.totalGasPrice.div(toBN(gasLimit)); const maxPriorityFeePerGas = feeMarket.maxPriorityFeePerGas; @@ -162,6 +172,35 @@ class Transaction { type: '0x02', accessList: this.tx.accessList || [], }; + const common = Common.custom({ + chainId: BigInt(this.tx.chainId), + defaultHardfork: Hardfork.London, + }); + let finalizedTransaction = FeeMarketEIP1559Transaction.fromTxData( + feeMarketTx as FinalizedFeeMarketEthereumTransaction, + { + common, + }, + ); + if (options.totalGasPrice) { + const opFee = await this.getOPfees(finalizedTransaction); + if (opFee.gtn(0)) { + const gasFeeWithoutOPFee = options.totalGasPrice.sub(opFee); + maxFeePerGas = gasFeeWithoutOPFee.div(toBN(gasLimit)); + feeMarketTx.maxFeePerGas = numberToHex(maxFeePerGas) as `0x${string}`; + feeMarketTx.maxPriorityFeePerGas = numberToHex( + maxPriorityFeePerGas.gt(maxFeePerGas) + ? maxFeePerGas + : maxPriorityFeePerGas, + ) as `0x${string}`; + finalizedTransaction = FeeMarketEIP1559Transaction.fromTxData( + feeMarketTx as FinalizedFeeMarketEthereumTransaction, + { + common, + }, + ); + } + } return { transaction: feeMarketTx, gasLimit: feeMarketTx.gasLimit, @@ -169,6 +208,7 @@ class Transaction { maxFeePerGas: numberToHex(feeMarket.maxFeePerGas), maxPriorityFeePerGas: numberToHex(feeMarket.maxPriorityFeePerGas), formattedFeeHistory, + finalizedTransaction, }; } } @@ -182,30 +222,8 @@ class Transaction { async getFinalizedTransaction( options: TransactionOptions, ): Promise { - const { transaction } = await this.finalizeTransaction(options); - - if (!transaction.maxFeePerGas) { - const common = Common.custom({ - chainId: BigInt(transaction.chainId), - }); - return LegacyTransaction.fromTxData( - transaction as FinalizedLegacyEthereumTransaction, - { - common, - }, - ); - } else { - const common = Common.custom({ - chainId: BigInt(transaction.chainId), - defaultHardfork: Hardfork.London, - }); - return FeeMarketEIP1559Transaction.fromTxData( - transaction as FinalizedFeeMarketEthereumTransaction, - { - common, - }, - ); - } + const { finalizedTransaction } = await this.finalizeTransaction(options); + return finalizedTransaction; } async getMessageToSign(options: TransactionOptions): Promise { @@ -214,35 +232,38 @@ class Transaction { } async getGasCosts(): Promise { - const { gasLimit, gasPrice, baseFeePerGas, formattedFeeHistory } = - await this.finalizeTransaction({ - gasPriceType: GasPriceTypes.ECONOMY, - }); - const opFee = await this.getOPfees(); + const { + gasLimit, + gasPrice, + baseFeePerGas, + formattedFeeHistory, + finalizedTransaction, + } = await this.finalizeTransaction({ + gasPriceType: GasPriceTypes.ECONOMY, + }); if (gasPrice) { return { [GasPriceTypes.ECONOMY]: numberToHex( - getGasBasedOnType(gasPrice, GasPriceTypes.ECONOMY) - .mul(toBN(gasLimit)) - .add(opFee), + getGasBasedOnType(gasPrice, GasPriceTypes.ECONOMY).mul( + toBN(gasLimit), + ), ), [GasPriceTypes.REGULAR]: numberToHex( - getGasBasedOnType(gasPrice, GasPriceTypes.REGULAR) - .mul(toBN(gasLimit)) - .add(opFee), + getGasBasedOnType(gasPrice, GasPriceTypes.REGULAR).mul( + toBN(gasLimit), + ), ), [GasPriceTypes.FAST]: numberToHex( - getGasBasedOnType(gasPrice, GasPriceTypes.FAST) - .mul(toBN(gasLimit)) - .add(opFee), + getGasBasedOnType(gasPrice, GasPriceTypes.FAST).mul(toBN(gasLimit)), ), [GasPriceTypes.FASTEST]: numberToHex( - getGasBasedOnType(gasPrice, GasPriceTypes.FASTEST) - .mul(toBN(gasLimit)) - .add(opFee), + getGasBasedOnType(gasPrice, GasPriceTypes.FASTEST).mul( + toBN(gasLimit), + ), ), }; } else { + const opFee = await this.getOPfees(finalizedTransaction); return { [GasPriceTypes.ECONOMY]: numberToHex( this.getFeeMarketGasInfo( From aa5c165be99d5bdc194c207409f6ff29a73d11aa Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:48:03 -0800 Subject: [PATCH 2/3] fix: hw wallet shaded area --- .../ui/action/views/swap/components/swap-error/index.vue | 2 +- .../ui/action/views/swap/components/swap-loading/index.vue | 2 +- .../ui/action/views/swap/views/swap-best-offer/index.vue | 6 +----- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/extension/src/ui/action/views/swap/components/swap-error/index.vue b/packages/extension/src/ui/action/views/swap/components/swap-error/index.vue index 5890dc1d7..3d48193ec 100644 --- a/packages/extension/src/ui/action/views/swap/components/swap-error/index.vue +++ b/packages/extension/src/ui/action/views/swap/components/swap-error/index.vue @@ -130,7 +130,7 @@ const supportedNets = getSupportedNetworks() &__container { width: 100%; - height: 600px; + height: 100%; left: 0px; top: 0px; position: fixed; diff --git a/packages/extension/src/ui/action/views/swap/components/swap-loading/index.vue b/packages/extension/src/ui/action/views/swap/components/swap-loading/index.vue index 3310af9ee..68a0a5968 100644 --- a/packages/extension/src/ui/action/views/swap/components/swap-loading/index.vue +++ b/packages/extension/src/ui/action/views/swap/components/swap-loading/index.vue @@ -84,7 +84,7 @@ withDefaults(defineProps(), { &__container { width: 100%; - height: 600px; + height: 100%; left: 0px; top: 0px; position: fixed; diff --git a/packages/extension/src/ui/action/views/swap/views/swap-best-offer/index.vue b/packages/extension/src/ui/action/views/swap/views/swap-best-offer/index.vue index 83090a272..24b04f7d3 100644 --- a/packages/extension/src/ui/action/views/swap/views/swap-best-offer/index.vue +++ b/packages/extension/src/ui/action/views/swap/views/swap-best-offer/index.vue @@ -11,11 +11,7 @@
- + Date: Tue, 26 Nov 2024 12:43:56 -0800 Subject: [PATCH 3/3] fix: bnb max send --- .../src/providers/ethereum/libs/transaction/gas-utils.ts | 2 +- packages/extension/src/providers/solana/libs/api.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/extension/src/providers/ethereum/libs/transaction/gas-utils.ts b/packages/extension/src/providers/ethereum/libs/transaction/gas-utils.ts index c2246bf1a..8abbb3228 100644 --- a/packages/extension/src/providers/ethereum/libs/transaction/gas-utils.ts +++ b/packages/extension/src/providers/ethereum/libs/transaction/gas-utils.ts @@ -62,7 +62,7 @@ const getGasBasedOnType = ( } }; const getMinPriorityFee = (): BNType => { - return toBN(toWei('0.1', 'gwei')); + return toBN(toWei('1', 'gwei')); }; const getPriorityFeeAvg = (arr: BNType[]): BNType => { const sum = arr.reduce((a, v) => a.add(v)); diff --git a/packages/extension/src/providers/solana/libs/api.ts b/packages/extension/src/providers/solana/libs/api.ts index e7d404a93..9931e7526 100644 --- a/packages/extension/src/providers/solana/libs/api.ts +++ b/packages/extension/src/providers/solana/libs/api.ts @@ -64,7 +64,7 @@ class API implements ProviderAPIInterface { } const allTokensResponse = await cacheFetch( { - url: 'https://utl.solcast.dev/solana-tokenlist.json', + url: 'https://raw.githubusercontent.com/solflare-wallet/token-list/refs/heads/master/solana-tokenlist.json', postProcess: (data: any) => { const allTokens = data.tokens as TokenDetails[]; const tObj: Record = {}; @@ -74,7 +74,7 @@ class API implements ProviderAPIInterface { return tObj; }, }, - 60 * 60 * 1000, + 6 * 60 * 60 * 1000, ); const allTokens = allTokensResponse as Record; let decimals = 9;