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

feat/release-2.0 #573

Merged
merged 40 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0e05267
feat: fail dropped jupiter transactions
NickKelly1 Nov 13, 2024
3ade320
chore: lint
NickKelly1 Nov 13, 2024
87d808c
fix: swap activity
NickKelly1 Nov 13, 2024
35775ee
feat: transaction and swap dropped status
NickKelly1 Nov 14, 2024
41931cd
chore: lint
NickKelly1 Nov 14, 2024
c0bbe9a
chore: cleanup
NickKelly1 Nov 14, 2024
216798b
Merge branch 'develop' into feat/fail-dropped-jupiter-transactions
NickKelly1 Nov 14, 2024
a28a95a
feat: add base to rango and changelly
NickKelly1 Nov 15, 2024
71749a2
fix: dropped jupiter sol swap transactions
NickKelly1 Nov 21, 2024
10dfeb0
fix: increase jupiter swap priority fee multiplier
NickKelly1 Nov 21, 2024
4e7071a
fix: base max fee
kvhnuke Nov 21, 2024
aa5c165
fix: hw wallet shaded area
kvhnuke Nov 21, 2024
f7ef55d
fix: send input ui breaking with multiple periods
NickKelly1 Nov 22, 2024
3e02753
feat: show dst network in swap activity desc when src and dst symbols…
NickKelly1 Nov 22, 2024
f14d212
chore: debug logger
NickKelly1 Nov 25, 2024
6b20354
chore: cleanup
NickKelly1 Nov 25, 2024
0ed9910
chore: cleanup
NickKelly1 Nov 25, 2024
1b5be68
chore: cleanup, enable debug logging with env vars
NickKelly1 Nov 26, 2024
d7a3e5d
chore: cleanup
NickKelly1 Nov 26, 2024
9ff1f9c
chore: cleanup
NickKelly1 Nov 26, 2024
1c45fd5
chore: improve typescript for global logging
NickKelly1 Nov 26, 2024
194ed30
chore: cleanup
NickKelly1 Nov 26, 2024
d1b8c83
fix: bnb max send
kvhnuke Nov 26, 2024
86fcadc
fix: evm solana send low balance error messages
NickKelly1 Nov 27, 2024
45b17a9
fix: send balance error messages
NickKelly1 Nov 27, 2024
c5db516
chore: cleanup
NickKelly1 Nov 27, 2024
787a7fc
chore: cleanup
NickKelly1 Nov 27, 2024
3293012
chore: cleanup
NickKelly1 Nov 27, 2024
7a4a969
chore: cleanup
NickKelly1 Nov 27, 2024
b0b77c0
Merge pull request #569 from enkryptcom/chore/debug-logger
kvhnuke Dec 4, 2024
741f728
Merge pull request #568 from enkryptcom/feat/activity-swap-descriptio…
kvhnuke Dec 4, 2024
b5b9fb0
Merge pull request #567 from enkryptcom/fix/send-input-ui-breaking-wi…
kvhnuke Dec 4, 2024
969ea9c
Merge pull request #565 from enkryptcom/fix/base-max-fee
kvhnuke Dec 4, 2024
775e897
Merge pull request #562 from enkryptcom/fix/dropped-jupiter-sol-swap-…
kvhnuke Dec 4, 2024
e49dcf7
devop: merge
kvhnuke Dec 4, 2024
7f0f6c3
Merge pull request #558 from enkryptcom/feat/add-base-to-rango-and-ch…
kvhnuke Dec 4, 2024
021167d
Merge pull request #553 from enkryptcom/feat/fail-dropped-jupiter-tra…
kvhnuke Dec 4, 2024
6b06a3f
fix: rtol ltol issue
kvhnuke Dec 6, 2024
3b2bfab
devop: add more unicode detections
kvhnuke Dec 6, 2024
9ec50d3
devop: add new network tags from bitrock and fraxtal
kvhnuke Dec 9, 2024
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: 2 additions & 0 deletions packages/extension/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# VITE_DEBUG_LOG="swap:*"
VITE_DEBUG_LOG=
7 changes: 7 additions & 0 deletions packages/extension/src/libs/activity-state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ActivityState {
this.getActivityId(options),
);
}

async updateActivity(
activity: Activity,
options: ActivityOptions,
Expand All @@ -75,24 +76,29 @@ class ActivityState {
});
await this.setActivitiesById(clone, this.getActivityId(options));
}

async setCacheTime(options: ActivityOptions): Promise<void> {
await this.#storage.set(this.getActivityCacheId(options), {
[STORAGE_KEY]: new Date().getTime(),
});
}

async getCacheTime(options: ActivityOptions): Promise<number> {
const cacheTime: Record<string, number> = await this.#storage.get(
this.getActivityCacheId(options),
);
if (!cacheTime || !cacheTime[STORAGE_KEY]) return 0;
return cacheTime[STORAGE_KEY];
}

async getAllActivities(options: ActivityOptions): Promise<Activity[]> {
return this.getActivitiesById(this.getActivityId(options));
}

async deleteAllActivities(options: ActivityOptions): Promise<void> {
this.setActivitiesById([], this.getActivityId(options));
}

kvhnuke marked this conversation as resolved.
Show resolved Hide resolved
private async setActivitiesById(
activities: Activity[],
id: string,
Expand All @@ -101,6 +107,7 @@ class ActivityState {
[STORAGE_KEY]: activities,
});
}

private async getActivitiesById(id: string): Promise<Activity[]> {
const allStates: Record<string, Activity[]> = await this.#storage.get(id);
if (!allStates || !allStates[STORAGE_KEY]) return [];
Expand Down
22 changes: 22 additions & 0 deletions packages/extension/src/libs/utils/unicode-detection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const fixedHex = (number: number, length: number) => {
let str = number.toString(16).toUpperCase();
while (str.length < length) str = '0' + str;
return str;
};
kvhnuke marked this conversation as resolved.
Show resolved Hide resolved

/* Creates a unicode literal based on the string */
const unicodeLiteral = (str: string) => {
let i;
let result = '';
for (i = 0; i < str.length; ++i) {
if (str.charCodeAt(i) > 126 || str.charCodeAt(i) < 32)
result += '\\u' + fixedHex(str.charCodeAt(i), 4);
else result += str[i];
}
return result;
};
export const getRTLOLTLOSafeString = (str: string): string => {
const dangerous = /[\u202A-\u202E\u2066-\u2069\u200E\u200F\u061C]/.test(str);
if (dangerous) return unicodeLiteral(str);
return str;
};
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { ProviderRequestOptions } from '@/types/provider';
import { BitcoinNetwork } from '../types/bitcoin-network';
import { EnkryptAccount } from '@enkryptcom/types';
import { MessageSigner } from './libs/signer';
import { getRTLOLTLOSafeString } from '@/libs/utils/unicode-detection';

const windowPromise = WindowPromiseHandler(4);
const network = ref<BitcoinNetwork>(DEFAULT_BTC_NETWORK);
Expand Down Expand Up @@ -92,7 +93,7 @@ onBeforeMount(async () => {
account.value = Request.value.params![2] as EnkryptAccount;
identicon.value = network.value.identicon(account.value.address);
Options.value = options;
message.value = Request.value.params![0];
message.value = getRTLOLTLOSafeString(Request.value.params![0]);
type.value = Request.value.params![1];
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ const isInputsValid = computed<boolean>(() => {
isSendToken.value
)
return false;
if (new BigNumber(sendAmount.value).gt(assetMaxValue.value)) return false;

const sendAmountBigNumber = new BigNumber(sendAmount.value)
if (sendAmountBigNumber.isNaN()) return false
if (sendAmountBigNumber.gt(assetMaxValue.value)) return false;
return true;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,16 @@ const amount = computed({

const onlyNumber = ($event: KeyboardEvent) => {
const keyCode = $event.keyCode ? $event.keyCode : $event.which;
if ((keyCode < 48 || keyCode > 57) && keyCode !== 46) {
$event.preventDefault();
// Numeric
if (keyCode >= /* 0 */ 48 && keyCode <= /* 9 */ 57) {
return;
}
// Only allow a single period
if (keyCode === /* '.' */ 46 && amount.value.indexOf('.') === -1) {
return;
}
// Alphabetical (/non-numeric) or mulitple periods. Don't propagate change
$event.preventDefault();
kvhnuke marked this conversation as resolved.
Show resolved Hide resolved
};
const changeFocus = () => {
isFocus.value = !isFocus.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
113 changes: 67 additions & 46 deletions packages/extension/src/providers/ethereum/libs/transaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ class Transaction {
value: this.tx.value || '0x0',
});
}
async getOPfees(): Promise<BNType> {
async getOPfees(
fTx: LegacyTransaction | FeeMarketEIP1559Transaction,
): Promise<BNType> {
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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -162,13 +172,43 @@ 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,
},
);
}
}
kvhnuke marked this conversation as resolved.
Show resolved Hide resolved
return {
transaction: feeMarketTx,
gasLimit: feeMarketTx.gasLimit,
baseFeePerGas: numberToHex(baseFeePerGas!),
maxFeePerGas: numberToHex(feeMarket.maxFeePerGas),
maxPriorityFeePerGas: numberToHex(feeMarket.maxPriorityFeePerGas),
formattedFeeHistory,
finalizedTransaction,
};
}
}
Expand All @@ -182,30 +222,8 @@ class Transaction {
async getFinalizedTransaction(
options: TransactionOptions,
): Promise<LegacyTransaction | FeeMarketEIP1559Transaction> {
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<Uint8Array> {
Expand All @@ -214,35 +232,38 @@ class Transaction {
}

async getGasCosts(): Promise<GasCosts> {
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(
Expand Down
6 changes: 3 additions & 3 deletions packages/extension/src/providers/ethereum/networks/maticzk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ const maticOptions: EvmNetworkOptions = {
blockExplorerAddr: 'https://zkevm.polygonscan.com/address/[[address]]',
chainID: '0x44d',
isTestNetwork: false,
currencyName: 'POL',
currencyNameLong: 'Polygon POL',
currencyName: 'ETH',
currencyNameLong: 'Ethereum',
node: 'wss://nodes.mewapi.io/ws/maticzk',
icon,
coingeckoID: 'polygon-ecosystem-token',
coingeckoID: 'ethereum',
coingeckoPlatform: CoingeckoPlatform.MaticZK,
NFTHandler: shNFTHandler,
assetsInfoHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import HardwareWalletMsg from '@/providers/common/ui/verify-transaction/hardware
import { EvmNetwork } from '../types/evm-network';
import { EnkryptAccount } from '@enkryptcom/types';
import { MessageSigner } from './libs/signer';
import { getRTLOLTLOSafeString } from '@/libs/utils/unicode-detection';

const windowPromise = WindowPromiseHandler(3);
const network = ref<EvmNetwork>(DEFAULT_EVM_NETWORK);
Expand All @@ -85,7 +86,7 @@ onBeforeMount(async () => {
identicon.value = network.value.identicon(account.value.address);
Options.value = options;
message.value = isUtf8(Request.value.params![0])
? hexToUtf8(Request.value.params![0])
? getRTLOLTLOSafeString(hexToUtf8(Request.value.params![0]))
: Request.value.params![0];
});

Expand Down
Loading
Loading