-
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?
Changes from 3 commits
1c5a986
9a47fa1
08373d2
b512343
3e12dd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,12 +181,21 @@ const useSendTransaction = ( | |
} | ||
const from = sourceTokenSelected.chain_name; | ||
const to = destinationTokenSelected.chain_name; | ||
const btc = bitcoinAddress; | ||
const token = sourceTokenSelected.symbol; | ||
const tx = await client.deposit({ | ||
chain: from, | ||
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"), | ||
}, | ||
Comment on lines
+189
to
+198
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. 🛠️ Refactor suggestion Refactor The 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,
});
|
||
}); | ||
if (track) { | ||
track({ | ||
|
@@ -253,10 +262,20 @@ const useSendTransaction = ( | |
console.error("ZRC-20 address not found"); | ||
return; | ||
} | ||
const tx = await client.withdraw({ | ||
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"), | ||
}, | ||
Comment on lines
+265
to
+278
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. 🛠️ Refactor suggestion Apply standardized constants for In the 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,
});
|
||
}); | ||
const token = sourceTokenSelected.symbol; | ||
const from = sourceTokenSelected.chain_name; | ||
|
@@ -277,10 +296,20 @@ const useSendTransaction = ( | |
const from = sourceTokenSelected.chain_name; | ||
const to = destinationTokenSelected.chain_name; | ||
const token = sourceTokenSelected.symbol; | ||
const tx = await client.deposit({ | ||
chain: from, | ||
const tx = await client.evmDeposit({ | ||
amount: sourceAmount, | ||
recipient: addressSelected, | ||
erc20: "", | ||
receiver: addressSelected, | ||
revertOptions: { | ||
callOnRevert: false, | ||
onRevertGasLimit: 7000000, | ||
revertAddress: "0x0000000000000000000000000000000000000000", | ||
revertMessage: "0x", | ||
}, | ||
txOptions: { | ||
gasLimit: 7000000, | ||
gasPrice: ethers.BigNumber.from("50000000000"), | ||
}, | ||
}); | ||
if (track) { | ||
track({ | ||
|
@@ -372,47 +401,31 @@ const useSendTransaction = ( | |
if (!sourceTokenSelected || !destinationTokenSelected) { | ||
return; | ||
} | ||
const custodyAddress = getAddress( | ||
"erc20Custody", | ||
sourceTokenSelected.chain_name as ParamChainName | ||
); | ||
const custodyContract = new ethers.Contract( | ||
custodyAddress as string, | ||
ERC20Custody.abi, | ||
client.signer | ||
); | ||
const assetAddress = sourceTokenSelected.contract; | ||
const amount = ethers.utils.parseUnits( | ||
sourceAmount, | ||
sourceTokenSelected.decimals | ||
); | ||
try { | ||
const contract = new ethers.Contract( | ||
assetAddress as string, | ||
ERC20_ABI.abi, | ||
client.signer | ||
); | ||
await (await contract.approve(custodyAddress, amount)).wait(); | ||
const tx = await custodyContract.deposit( | ||
addressSelected, | ||
assetAddress, | ||
amount, | ||
"0x" | ||
); | ||
await tx.wait(); | ||
const token = sourceTokenSelected.symbol; | ||
const from = sourceTokenSelected.chain_name; | ||
const dest = destinationTokenSelected.chain_name; | ||
if (track) { | ||
track({ | ||
hash: tx.hash, | ||
desc: `Sent ${sourceAmount} ${token} from ${from} to ${dest}`, | ||
}); | ||
} | ||
console.log(tx.hash); | ||
} catch (error) { | ||
console.error("Error during deposit: ", error); | ||
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); | ||
Comment on lines
+404
to
+428
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. 🛠️ Refactor suggestion Refactor In the 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"),
+ },
});
|
||
}; | ||
|
||
m.transferBTC = async () => { | ||
|
@@ -449,19 +462,25 @@ const useSendTransaction = ( | |
} | ||
const d = destinationTokenSelected; | ||
const zrc20 = d.coin_type === "ZRC20" ? d.contract : d.zrc20; | ||
const params = { | ||
chain: from, | ||
let tx; | ||
tx = await client.evmDepositAndCall({ | ||
amount: sourceAmount, | ||
recipient: omnichainSwapContractAddress, | ||
message: [ | ||
["address", "bytes", "bool"], | ||
[zrc20, recipient, withdraw], | ||
], | ||
erc20: sourceTokenSelected.contract, | ||
}; | ||
console.log("swap", params); | ||
const tx = await client.deposit(params); | ||
|
||
receiver: omnichainSwapContractAddress, | ||
revertOptions: { | ||
callOnRevert: false, | ||
onRevertGasLimit: 7000000, | ||
revertAddress: "0x0000000000000000000000000000000000000000", | ||
revertMessage: "0x", | ||
}, | ||
txOptions: { | ||
gasLimit: 7000000, | ||
gasPrice: ethers.BigNumber.from("10000000000"), | ||
}, | ||
types: ["address", "bytes", "bool"], | ||
values: [zrc20, recipient, withdraw.toString()], | ||
}); | ||
console.log(tx); | ||
if (tx && track) { | ||
track({ | ||
hash: 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.
Ensure
bitcoinAddress
is validated before usageIn the
withdrawBTC
function,bitcoinAddress
is used as thereceiver
parameter without prior validation. IfbitcoinAddress
isundefined
, it could lead to runtime errors or unintended behavior during transaction execution.Apply this diff to add a validation check for
bitcoinAddress
: