Skip to content

Commit

Permalink
update toolkit version, use latest toolkit function for useSendTransa…
Browse files Browse the repository at this point in the history
…ction hook
  • Loading branch information
lukema95 committed Dec 24, 2024
1 parent 4f1a3c2 commit 1c5a986
Show file tree
Hide file tree
Showing 3 changed files with 445 additions and 115 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@web3-name-sdk/core": "^0.2.0",
"@zetachain/protocol-contracts": "^9.0.0",
"@zetachain/networks": "^10.0.0",
"@zetachain/toolkit": "^12.0.0",
"@zetachain/toolkit": "^13.0.0-rc8",
"autoprefixer": "^10.4.19",
"bech32": "^2.0.0",
"class-variance-authority": "^0.7.0",
Expand Down
111 changes: 62 additions & 49 deletions src/components/Swap/hooks/useSendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
});
if (track) {
track({
Expand Down Expand Up @@ -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"),
},
});
const token = sourceTokenSelected.symbol;
const from = sourceTokenSelected.chain_name;
Expand All @@ -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({
Expand Down Expand Up @@ -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);
};

m.transferBTC = async () => {
Expand Down
Loading

0 comments on commit 1c5a986

Please sign in to comment.