Skip to content

Commit 3f605e5

Browse files
authored
Merge pull request #434 from multiversx/development
Add isGuarded prop (#433)
2 parents edc5628 + 3c66fa8 commit 3f605e5

File tree

10 files changed

+208
-66
lines changed

10 files changed

+208
-66
lines changed

pnpm-lock.yaml

Lines changed: 166 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/localConstants/gas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const GUARDED_TX_EXTRA_GAS_LIMIT = 50_000;

src/pages/Dashboard/widgets/BatchTransactions/BatchTransactions.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { useState } from 'react';
21
import {
32
faArrowsRotate,
43
faPaperPlane,
54
IconDefinition
65
} from '@fortawesome/free-solid-svg-icons';
76
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
7+
import { useState } from 'react';
88
import { OutputContainer } from 'components/OutputContainer';
99
import { TransactionsOutput } from 'components/OutputContainer/components';
1010
import { MvxButton, useGetPendingTransactionsSessions } from 'lib';
@@ -35,7 +35,7 @@ interface BatchTransactionsButtonsType {
3535
}
3636

3737
export const BatchTransactions = () => {
38-
const { address, nonce } = useGetAccount();
38+
const { address, nonce, isGuarded } = useGetAccount();
3939
const { network } = useGetNetworkConfig();
4040
const [currentSessionId, setCurrentSessionId] = useState('');
4141
const pendingSession = useGetPendingTransactionsSessions();
@@ -47,6 +47,7 @@ export const BatchTransactions = () => {
4747

4848
const executeSignAndAutoSendBatchTransactions = async () => {
4949
const sessionId = await signAndAutoSendBatchTransactions({
50+
isGuarded,
5051
address,
5152
nonce,
5253
chainID: network.chainId,
@@ -63,6 +64,7 @@ export const BatchTransactions = () => {
6364

6465
const executeWrapMultiTransferTransactions = async () => {
6566
const sessionId = await wrapAndMultiTransferTransactions({
67+
isGuarded,
6668
address,
6769
nonce,
6870
chainID: network.chainId,
@@ -79,6 +81,7 @@ export const BatchTransactions = () => {
7981

8082
const executeSwapAndLockTokens = async () => {
8183
const sessionId = await swapAndLockTokens({
84+
isGuarded,
8285
address,
8386
nonce,
8487
chainID: network.chainId,

src/pages/Dashboard/widgets/BatchTransactions/helpers/getBatchTransactions.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import {
55
TransactionsFactoryConfig,
66
TransferTransactionsFactory
77
} from 'lib';
8+
import { GUARDED_TX_EXTRA_GAS_LIMIT } from 'localConstants/gas';
89
import { TransactionProps } from 'types';
910

1011
const NUMBER_OF_TRANSACTIONS = 5;
1112

1213
export const getBatchTransactions = async ({
1314
address,
14-
chainID
15+
chainID,
16+
isGuarded
1517
}: TransactionProps): Promise<Transaction[]> => {
1618
const transactions = Array.from(Array(NUMBER_OF_TRANSACTIONS).keys());
1719

@@ -35,6 +37,11 @@ export const getBatchTransactions = async ({
3537
}
3638
);
3739

40+
if (isGuarded) {
41+
tokenTransfer.gasLimit =
42+
tokenTransfer.gasLimit + BigInt(GUARDED_TX_EXTRA_GAS_LIMIT);
43+
}
44+
3845
return tokenTransfer;
3946
})
4047
);

src/pages/Dashboard/widgets/BatchTransactions/helpers/getSwapAndLockTransactions.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { BATCH_TRANSACTIONS_SC } from 'config';
22
import { Address, GAS_PRICE, Transaction, VERSION } from 'lib';
3+
import { GUARDED_TX_EXTRA_GAS_LIMIT } from 'localConstants/gas';
34
import { TransactionProps } from 'types';
45

56
export const getSwapAndLockTransactions = ({
7+
isGuarded,
68
address,
79
chainID,
810
nonce
911
}: TransactionProps): Transaction[] => {
10-
return [
12+
const transactions = [
1113
new Transaction({
1214
chainID,
1315
gasLimit: BigInt(4200000),
@@ -57,4 +59,12 @@ export const getSwapAndLockTransactions = ({
5759
data: Uint8Array.from(Buffer.from(BATCH_TRANSACTIONS_SC.lock_MEX.data))
5860
})
5961
];
62+
63+
if (isGuarded) {
64+
transactions.forEach((tx) => {
65+
tx.gasLimit = tx.gasLimit + BigInt(GUARDED_TX_EXTRA_GAS_LIMIT);
66+
});
67+
}
68+
69+
return transactions;
6070
};

src/pages/Dashboard/widgets/BatchTransactions/helpers/getWrapAndMultiTransferTransactions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import {
1010
import { BATCH_TRANSACTIONS_SC } from 'config';
1111
import { contractAddress } from 'config';
1212
import { Address } from 'lib';
13+
import { GUARDED_TX_EXTRA_GAS_LIMIT } from 'localConstants/gas';
1314
import { TransactionProps } from 'types';
1415

1516
export const getWrapAndMultiTransferTransactions = async ({
17+
isGuarded,
1618
address,
1719
chainID
1820
}: TransactionProps) => {
@@ -68,5 +70,13 @@ export const getWrapAndMultiTransferTransactions = async ({
6870
]
6971
});
7072

73+
if (isGuarded) {
74+
[wrapOneEgld, swapHalfWEgldToUsdc, multiTransferOneUsdcHalfWEgld].forEach(
75+
(tx) => {
76+
tx.gasLimit += BigInt(GUARDED_TX_EXTRA_GAS_LIMIT);
77+
}
78+
);
79+
}
80+
7181
return { wrapOneEgld, swapHalfWEgldToUsdc, multiTransferOneUsdcHalfWEgld };
7282
};

src/pages/Dashboard/widgets/BatchTransactions/helpers/signAndAutoSendBatchTransactions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getBatchTransactions } from './getBatchTransactions';
44
import { sendAndTrackTransactions } from './sendAndTrackTransactions';
55

66
export const signAndAutoSendBatchTransactions = async ({
7+
isGuarded,
78
address,
89
nonce,
910
chainID,
@@ -18,6 +19,7 @@ export const signAndAutoSendBatchTransactions = async ({
1819
const provider = getAccountProvider();
1920

2021
const transactions = await getBatchTransactions({
22+
isGuarded,
2123
address,
2224
nonce,
2325
chainID

src/pages/Dashboard/widgets/BatchTransactions/helpers/swapAndLockTokens.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getSwapAndLockTransactions } from './getSwapAndLockTransactions';
1010
import { sendAndTrackTransactions } from './sendAndTrackTransactions';
1111

1212
export const swapAndLockTokens = async ({
13+
isGuarded,
1314
address,
1415
nonce,
1516
chainID,
@@ -24,6 +25,7 @@ export const swapAndLockTokens = async ({
2425
const provider = getAccountProvider();
2526

2627
const transactionsToSign = getSwapAndLockTransactions({
28+
isGuarded,
2729
address,
2830
chainID,
2931
nonce

src/pages/Dashboard/widgets/BatchTransactions/helpers/wrapAndMultiTransferTransactions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ interface WrapAndMultiTransferTransactionsType extends TransactionProps {
1414
export const wrapAndMultiTransferTransactions = async (
1515
props: WrapAndMultiTransferTransactionsType
1616
) => {
17-
const { address, nonce, chainID, transactionsDisplayInfo } = props;
17+
const { address, nonce, chainID, transactionsDisplayInfo, isGuarded } = props;
1818

1919
const provider = getAccountProvider();
2020

2121
const transactionsToSign = await getWrapAndMultiTransferTransactions({
22+
isGuarded,
2223
address,
2324
chainID,
2425
nonce

src/types/transaction.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export type TransactionProps = {
2+
isGuarded?: boolean;
23
address: string;
34
nonce: number;
45
chainID: string;

0 commit comments

Comments
 (0)