-
Notifications
You must be signed in to change notification settings - Fork 4
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: Use latest toolkit function for useSendTransaction hook #31
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe pull request introduces a focused update to the project's dependency management and transaction handling mechanisms. The changes center around updating the Changes
Sequence DiagramsequenceDiagram
participant Client
participant Transaction Hook
participant Blockchain
Client->>Transaction Hook: Initiate Transaction
Transaction Hook->>Blockchain: zetachainWithdraw (BTC)
Transaction Hook->>Blockchain: zetachainWithdraw (ZRC20)
Transaction Hook->>Blockchain: evmDeposit (Native)
Transaction Hook->>Blockchain: evmDeposit (ERC20)
Transaction Hook->>Blockchain: evmDepositAndCall
The sequence diagram illustrates the updated transaction flow, showcasing the new method calls for different transaction types across various blockchain interactions. Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Have tested: DepositAndSwap
DepositDeposit tBNB(bsc_testnet) |
@fadeev pls review |
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.
Actionable comments posted: 4
🔭 Outside diff range comments (1)
src/components/Swap/hooks/useSendTransaction.ts (1)
Line range hint
185-483
: Standardize gas price values across transactionsThere is inconsistency in the
gasPrice
values specified in different functions (10000000000
and50000000000
). To ensure predictable transaction costs and avoid potential overpayment, consider standardizing thegasPrice
or making it configurable based on network conditions.Example adjustment:
const TX_OPTIONS_STANDARD = { gasLimit: 7_000_000, - gasPrice: ethers.BigNumber.from("10_000_000_000"), + gasPrice: ethers.BigNumber.from("50_000_000_000"), // Adjusted for consistency };
🧹 Nitpick comments (2)
src/components/Swap/hooks/useSendTransaction.ts (2)
299-312
: Utilize constants for transaction options indepositNative
The
depositNative
function redefinesrevertOptions
andtxOptions
. Consistently applying the extracted constants will reduce redundancy.Update the function accordingly:
const tx = await client.evmDeposit({ amount: sourceAmount, erc20: "", receiver: addressSelected, - revertOptions: { - callOnRevert: false, - onRevertGasLimit: 7000000, - revertAddress: "0x0000000000000000000000000000000000000000", - revertMessage: "0x", - }, + revertOptions: REVERT_OPTIONS, - txOptions: { - gasLimit: 7000000, - gasPrice: ethers.BigNumber.from("50000000000"), - }, + txOptions: { + ...TX_OPTIONS_STANDARD, + gasPrice: ethers.BigNumber.from("50_000_000_000"), + }, });
465-483
: Consolidate transaction options incrossChainSwapHandle
The
crossChainSwapHandle
function definestxOptions
andrevertOptions
inline. For consistency and maintainability, use the predefined constants.Adjust the function to incorporate the constants:
let tx; tx = await client.evmDepositAndCall({ amount: sourceAmount, erc20: sourceTokenSelected.contract, receiver: omnichainSwapContractAddress, - revertOptions: { - callOnRevert: false, - onRevertGasLimit: 7000000, - revertAddress: "0x0000000000000000000000000000000000000000", - revertMessage: "0x", - }, + revertOptions: REVERT_OPTIONS, - txOptions: { - gasLimit: 7000000, - gasPrice: ethers.BigNumber.from("10000000000"), - }, + txOptions: TX_OPTIONS_STANDARD, types: ["address", "bytes", "bool"], values: [zrc20, recipient, withdraw.toString()], });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
📒 Files selected for processing (2)
package.json
(1 hunks)src/components/Swap/hooks/useSendTransaction.ts
(5 hunks)
🔇 Additional comments (1)
package.json (1)
37-37
: Verify compatibility of the updated@zetachain/toolkit
dependencyThe
@zetachain/toolkit
version has been updated to"13.0.0-rc10"
, a pre-release candidate. Ensure that this version is stable for production use and compatible with the existing codebase. Pre-release versions may contain breaking changes or unresolved issues.Consider running comprehensive tests to confirm that the updated toolkit functions as expected with your application.
const tx = await client.zetachainWithdraw({ | ||
amount: sourceAmount, | ||
recipient: addressSelected, | ||
zrc20: sourceTokenSelected.contract, | ||
receiver: bitcoinAddress, | ||
revertOptions: { | ||
callOnRevert: false, | ||
onRevertGasLimit: 7000000, | ||
revertAddress: "0x0000000000000000000000000000000000000000", | ||
revertMessage: "0x", | ||
}, | ||
txOptions: { | ||
gasLimit: 7000000, | ||
gasPrice: ethers.BigNumber.from("10000000000"), | ||
}, |
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.
Ensure bitcoinAddress
is validated before usage
In the withdrawBTC
function, bitcoinAddress
is used as the receiver
parameter without prior validation. If bitcoinAddress
is undefined
, it could lead to runtime errors or unintended behavior during transaction execution.
Apply this diff to add a validation check for bitcoinAddress
:
m.withdrawBTC = async () => {
if (!sourceTokenSelected || !destinationTokenSelected) {
return;
}
+ if (!bitcoinAddress) {
+ throw new Error("Bitcoin address is undefined.");
+ }
const from = sourceTokenSelected.chain_name;
const to = destinationTokenSelected.chain_name;
const token = sourceTokenSelected.symbol;
Committable suggestion skipped: line range outside the PR's diff.
const tx = await client.zetachainWithdraw({ | ||
amount: sourceAmount, | ||
zrc20, | ||
recipient: addressSelected, | ||
receiver: addressSelected, | ||
revertOptions: { | ||
callOnRevert: false, | ||
onRevertGasLimit: 7000000, | ||
revertAddress: "0x0000000000000000000000000000000000000000", | ||
revertMessage: "0x", | ||
}, | ||
txOptions: { | ||
gasLimit: 7000000, | ||
gasPrice: ethers.BigNumber.from("10000000000"), | ||
}, |
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.
🛠️ Refactor suggestion
Apply standardized constants for revertOptions
and txOptions
In the withdrawZRC20
function, the same revertOptions
and txOptions
are redefined. Utilize the previously extracted constants to enhance consistency and maintainability.
Modify the function to use the constants:
const tx = await client.zetachainWithdraw({
amount: sourceAmount,
zrc20,
receiver: addressSelected,
- revertOptions: {
- callOnRevert: false,
- onRevertGasLimit: 7000000,
- revertAddress: "0x0000000000000000000000000000000000000000",
- revertMessage: "0x",
- },
+ revertOptions: REVERT_OPTIONS,
- txOptions: {
- gasLimit: 7000000,
- gasPrice: ethers.BigNumber.from("10000000000"),
- },
+ txOptions: TX_OPTIONS_STANDARD,
});
Committable suggestion skipped: line range outside the PR's diff.
const from = sourceTokenSelected.chain_name; | ||
const to = destinationTokenSelected.chain_name; | ||
const token = sourceTokenSelected.symbol; | ||
const tx = await client.evmDeposit({ | ||
amount: sourceAmount, | ||
erc20: sourceTokenSelected.contract, | ||
receiver: addressSelected, | ||
revertOptions: { | ||
callOnRevert: false, | ||
onRevertGasLimit: 7000000, | ||
revertAddress: "0x0000000000000000000000000000000000000000", | ||
revertMessage: "0x", | ||
}, | ||
txOptions: { | ||
gasLimit: 7000000, | ||
gasPrice: ethers.BigNumber.from("50000000000"), | ||
}, | ||
}); | ||
if (track) { | ||
track({ | ||
hash: tx.hash, | ||
desc: `Sent ${sourceAmount} ${token} from ${from} to ${to}`, | ||
}); | ||
} | ||
console.log(tx.hash); |
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.
🛠️ Refactor suggestion
Refactor depositERC20
to use standardized options
In the depositERC20
function, revertOptions
and txOptions
are again duplicated. Apply the constants to maintain uniformity across transaction functions.
Revise the function as follows:
const tx = await client.evmDeposit({
amount: sourceAmount,
erc20: sourceTokenSelected.contract,
receiver: addressSelected,
- revertOptions: {
- callOnRevert: false,
- onRevertGasLimit: 7000000,
- revertAddress: "0x0000000000000000000000000000000000000000",
- revertMessage: "0x",
- },
+ revertOptions: REVERT_OPTIONS,
- txOptions: {
- gasLimit: 7000000,
- gasPrice: ethers.BigNumber.from("50000000000"),
- },
+ txOptions: {
+ ...TX_OPTIONS_STANDARD,
+ gasPrice: ethers.BigNumber.from("50_000_000_000"),
+ },
});
Committable suggestion skipped: line range outside the PR's diff.
revertOptions: { | ||
callOnRevert: false, | ||
onRevertGasLimit: 7000000, | ||
revertAddress: "0x0000000000000000000000000000000000000000", | ||
revertMessage: "0x", | ||
}, | ||
txOptions: { | ||
gasLimit: 7000000, | ||
gasPrice: ethers.BigNumber.from("10000000000"), | ||
}, |
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.
🛠️ Refactor suggestion
Refactor revertOptions
and txOptions
into reusable constants
The revertOptions
and txOptions
objects are duplicated across multiple functions, which hampers maintainability and increases the risk of inconsistencies. Extracting these into constants will promote code reuse and simplify future updates.
Define the constants at the appropriate scope:
+const REVERT_OPTIONS = {
+ callOnRevert: false,
+ onRevertGasLimit: 7_000_000,
+ revertAddress: "0x0000000000000000000000000000000000000000",
+ revertMessage: "0x",
+};
+const TX_OPTIONS_STANDARD = {
+ gasLimit: 7_000_000,
+ gasPrice: ethers.BigNumber.from("10_000_000_000"),
+};
m.withdrawBTC = async () => {
// Existing code...
const tx = await client.zetachainWithdraw({
amount: sourceAmount,
zrc20: sourceTokenSelected.contract,
receiver: bitcoinAddress,
- revertOptions: {
- callOnRevert: false,
- onRevertGasLimit: 7000000,
- revertAddress: "0x0000000000000000000000000000000000000000",
- revertMessage: "0x",
- },
+ revertOptions: REVERT_OPTIONS,
- txOptions: {
- gasLimit: 7000000,
- gasPrice: ethers.BigNumber.from("10000000000"),
- },
+ txOptions: TX_OPTIONS_STANDARD,
});
Committable suggestion skipped: line range outside the PR's diff.
issue: #30
Summary by CodeRabbit
Dependency Update
@zetachain/toolkit
to version13.0.0-rc10
Transaction Handling Improvements