Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
227 changes: 166 additions & 61 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useState } from 'react';
import {
faArrowsRotate,
faPaperPlane,
IconDefinition
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { useState } from 'react';
import { OutputContainer } from 'components/OutputContainer';
import { TransactionsOutput } from 'components/OutputContainer/components';
import { MvxButton, useGetPendingTransactionsSessions } from 'lib';
Expand Down Expand Up @@ -35,7 +35,7 @@ interface BatchTransactionsButtonsType {
}

export const BatchTransactions = () => {
const { address, nonce } = useGetAccount();
const { address, nonce, isGuarded } = useGetAccount();
const { network } = useGetNetworkConfig();
const [currentSessionId, setCurrentSessionId] = useState('');
const pendingSession = useGetPendingTransactionsSessions();
Expand All @@ -47,6 +47,7 @@ export const BatchTransactions = () => {

const executeSignAndAutoSendBatchTransactions = async () => {
const sessionId = await signAndAutoSendBatchTransactions({
isGuarded,
address,
nonce,
chainID: network.chainId,
Expand All @@ -63,6 +64,7 @@ export const BatchTransactions = () => {

const executeWrapMultiTransferTransactions = async () => {
const sessionId = await wrapAndMultiTransferTransactions({
isGuarded,
address,
nonce,
chainID: network.chainId,
Expand All @@ -79,6 +81,7 @@ export const BatchTransactions = () => {

const executeSwapAndLockTokens = async () => {
const sessionId = await swapAndLockTokens({
isGuarded,
address,
nonce,
chainID: network.chainId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const NUMBER_OF_TRANSACTIONS = 5;

export const getBatchTransactions = async ({
address,
chainID
chainID,
isGuarded
}: TransactionProps): Promise<Transaction[]> => {
const transactions = Array.from(Array(NUMBER_OF_TRANSACTIONS).keys());

Expand All @@ -35,6 +36,10 @@ export const getBatchTransactions = async ({
}
);

if (isGuarded) {
tokenTransfer.gasLimit = tokenTransfer.gasLimit + BigInt(50_000);
}
Comment on lines 40 to 43

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The value 50_000 is a magic number. It would be better to define it as a named constant, for example GAS_LIMIT_ADDITIONAL_FOR_GUARDED_ACCOUNT, in a shared configuration file (e.g., src/config/index.ts). This improves readability and maintainability, as the value is used in multiple places (getSwapAndLockTransactions.ts, getWrapAndMultiTransferTransactions.ts).

For example:

// src/config/constants.ts
export const GAS_LIMIT_ADDITIONAL_FOR_GUARDED_ACCOUNT = 50_000;

// Then in this file:
import { GAS_LIMIT_ADDITIONAL_FOR_GUARDED_ACCOUNT } from 'config/constants';
// ...
if (isGuarded) {
  tokenTransfer.gasLimit += BigInt(GAS_LIMIT_ADDITIONAL_FOR_GUARDED_ACCOUNT);
}


return tokenTransfer;
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { Address, GAS_PRICE, Transaction, VERSION } from 'lib';
import { TransactionProps } from 'types';

export const getSwapAndLockTransactions = ({
isGuarded,
address,
chainID,
nonce
}: TransactionProps): Transaction[] => {
return [
const transcations = [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's a typo in the variable name transcations. It should be transactions. This should be corrected here and in its usages on lines 63 and 68.

Suggested change
const transcations = [
const transactions = [

new Transaction({
chainID,
gasLimit: BigInt(4200000),
Expand Down Expand Up @@ -57,4 +58,12 @@ export const getSwapAndLockTransactions = ({
data: Uint8Array.from(Buffer.from(BATCH_TRANSACTIONS_SC.lock_MEX.data))
})
];

if (isGuarded) {
transcations.forEach((tx) => {
tx.gasLimit = tx.gasLimit + BigInt(50_000);
});
}

return transcations;
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Address } from 'lib';
import { TransactionProps } from 'types';

export const getWrapAndMultiTransferTransactions = async ({
isGuarded,
address,
chainID
}: TransactionProps) => {
Expand Down Expand Up @@ -68,5 +69,13 @@ export const getWrapAndMultiTransferTransactions = async ({
]
});

if (isGuarded) {
wrapOneEgld.gasLimit = wrapOneEgld.gasLimit + BigInt(50_000);
swapHalfWEgldToUsdc.gasLimit =
swapHalfWEgldToUsdc.gasLimit + BigInt(50_000);
multiTransferOneUsdcHalfWEgld.gasLimit =
multiTransferOneUsdcHalfWEgld.gasLimit + BigInt(50_000);
}
Comment on lines 73 to 79

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block of code is repetitive. You could group the transactions into an array and iterate over them to add the extra gas limit, similar to how it's done in getSwapAndLockTransactions.ts. This would make the code more concise and easier to maintain if more transactions are added in the future.

Also, as mentioned in another comment, the magic number 50_000 should be replaced with a named constant.

Suggested change
if (isGuarded) {
wrapOneEgld.gasLimit = wrapOneEgld.gasLimit + BigInt(50_000);
swapHalfWEgldToUsdc.gasLimit =
swapHalfWEgldToUsdc.gasLimit + BigInt(50_000);
multiTransferOneUsdcHalfWEgld.gasLimit =
multiTransferOneUsdcHalfWEgld.gasLimit + BigInt(50_000);
}
if (isGuarded) {
[wrapOneEgld, swapHalfWEgldToUsdc, multiTransferOneUsdcHalfWEgld].forEach(
(tx) => {
tx.gasLimit += BigInt(50_000);
}
);
}


return { wrapOneEgld, swapHalfWEgldToUsdc, multiTransferOneUsdcHalfWEgld };
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getBatchTransactions } from './getBatchTransactions';
import { sendAndTrackTransactions } from './sendAndTrackTransactions';

export const signAndAutoSendBatchTransactions = async ({
isGuarded,
address,
nonce,
chainID,
Expand All @@ -18,6 +19,7 @@ export const signAndAutoSendBatchTransactions = async ({
const provider = getAccountProvider();

const transactions = await getBatchTransactions({
isGuarded,
address,
nonce,
chainID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getSwapAndLockTransactions } from './getSwapAndLockTransactions';
import { sendAndTrackTransactions } from './sendAndTrackTransactions';

export const swapAndLockTokens = async ({
isGuarded,
address,
nonce,
chainID,
Expand All @@ -24,6 +25,7 @@ export const swapAndLockTokens = async ({
const provider = getAccountProvider();

const transactionsToSign = getSwapAndLockTransactions({
isGuarded,
address,
chainID,
nonce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ interface WrapAndMultiTransferTransactionsType extends TransactionProps {
export const wrapAndMultiTransferTransactions = async (
props: WrapAndMultiTransferTransactionsType
) => {
const { address, nonce, chainID, transactionsDisplayInfo } = props;
const { address, nonce, chainID, transactionsDisplayInfo, isGuarded } = props;

const provider = getAccountProvider();

const transactionsToSign = await getWrapAndMultiTransferTransactions({
isGuarded,
address,
chainID,
nonce
Expand Down
1 change: 1 addition & 0 deletions src/types/transaction.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type TransactionProps = {
isGuarded?: boolean;
address: string;
nonce: number;
chainID: string;
Expand Down