-
Notifications
You must be signed in to change notification settings - Fork 83
Add isGuarded prop (#433) #434
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 = [ | ||
|
||
| new Transaction({ | ||
| chainID, | ||
| gasLimit: BigInt(4200000), | ||
|
|
@@ -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 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ import { Address } from 'lib'; | |||||||||||||||||||||||||||||
| import { TransactionProps } from 'types'; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export const getWrapAndMultiTransferTransactions = async ({ | ||||||||||||||||||||||||||||||
| isGuarded, | ||||||||||||||||||||||||||||||
| address, | ||||||||||||||||||||||||||||||
| chainID | ||||||||||||||||||||||||||||||
| }: TransactionProps) => { | ||||||||||||||||||||||||||||||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 Also, as mentioned in another comment, the magic number
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return { wrapOneEgld, swapHalfWEgldToUsdc, multiTransferOneUsdcHalfWEgld }; | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
| 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; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value
50_000is a magic number. It would be better to define it as a named constant, for exampleGAS_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: