Skip to content
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
227 changes: 166 additions & 61 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/localConstants/gas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const GUARDED_TX_EXTRA_GAS_LIMIT = 50_000;
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 @@ -5,13 +5,15 @@ import {
TransactionsFactoryConfig,
TransferTransactionsFactory
} from 'lib';
import { GUARDED_TX_EXTRA_GAS_LIMIT } from 'localConstants/gas';
import { TransactionProps } from 'types';

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 +37,11 @@ export const getBatchTransactions = async ({
}
);

if (isGuarded) {
tokenTransfer.gasLimit =
tokenTransfer.gasLimit + BigInt(GUARDED_TX_EXTRA_GAS_LIMIT);
}

return tokenTransfer;
})
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { BATCH_TRANSACTIONS_SC } from 'config';
import { Address, GAS_PRICE, Transaction, VERSION } from 'lib';
import { GUARDED_TX_EXTRA_GAS_LIMIT } from 'localConstants/gas';
import { TransactionProps } from 'types';

export const getSwapAndLockTransactions = ({
isGuarded,
address,
chainID,
nonce
}: TransactionProps): Transaction[] => {
return [
const transactions = [
new Transaction({
chainID,
gasLimit: BigInt(4200000),
Expand Down Expand Up @@ -57,4 +59,12 @@ export const getSwapAndLockTransactions = ({
data: Uint8Array.from(Buffer.from(BATCH_TRANSACTIONS_SC.lock_MEX.data))
})
];

if (isGuarded) {
transactions.forEach((tx) => {
tx.gasLimit = tx.gasLimit + BigInt(GUARDED_TX_EXTRA_GAS_LIMIT);
});
}

return transactions;
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import {
import { BATCH_TRANSACTIONS_SC } from 'config';
import { contractAddress } from 'config';
import { Address } from 'lib';
import { GUARDED_TX_EXTRA_GAS_LIMIT } from 'localConstants/gas';
import { TransactionProps } from 'types';

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

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

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