Skip to content

Commit

Permalink
switch to approve
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Oct 7, 2024
1 parent ded9f42 commit b6a8ca3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
10 changes: 6 additions & 4 deletions examples/hello/contracts/Hello.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ contract Hello is UniversalContract {
RevertOptions memory revertOptions
) external {
(, uint256 gasFee) = IZRC20(zrc20).withdrawGasFeeWithGasLimit(gasLimit);
IZRC20(zrc20).transferFrom(msg.sender, address(this), gasFee);
IZRC20(zrc20).approve(address(gateway), gasFee);
gateway.call(receiver, zrc20, message, gasLimit, revertOptions);
}

Check warning

Code scanning / Slither

Unused return Medium

Check warning

Code scanning / Slither

Unused return Medium

Check failure

Code scanning / Slither

Unchecked transfer High

Expand All @@ -52,10 +53,11 @@ contract Hello is UniversalContract {
) external {
(address gasZRC20, uint256 gasFee) = IZRC20(zrc20)
.withdrawGasFeeWithGasLimit(gasLimit);
if (zrc20 == gasZRC20) {
IZRC20(zrc20).approve(address(gateway), amount + gasFee);
} else {
IZRC20(zrc20).approve(address(gateway), amount);
uint256 total = zrc20 == gasZRC20 ? amount + gasFee : amount;
IZRC20(zrc20).transferFrom(msg.sender, address(this), total);
IZRC20(zrc20).approve(address(gateway), total);
if (zrc20 != gasZRC20) {
IZRC20(gasZRC20).transferFrom(msg.sender, address(this), gasFee);
IZRC20(gasZRC20).approve(address(gateway), gasFee);
}
gateway.withdrawAndCall(
Expand Down
6 changes: 1 addition & 5 deletions examples/hello/tasks/helloCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const gasLimit = hre.ethers.BigNumber.from(args.txOptionsGasLimit);
const zrc20 = new ethers.Contract(args.zrc20, ZRC20ABI.abi, signer);
const [, gasFee] = await zrc20.withdrawGasFeeWithGasLimit(gasLimit);
const zrc20TransferTx = await zrc20.transfer(
args.contract,
gasFee,
txOptions
);
const zrc20TransferTx = await zrc20.approve(args.contract, gasFee, txOptions);

await zrc20TransferTx.wait();

Expand Down
8 changes: 4 additions & 4 deletions examples/hello/tasks/helloWithdrawAndCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const zrc20 = new ethers.Contract(args.zrc20, ZRC20ABI.abi, signer);
const [gasZRC20, gasFee] = await zrc20.withdrawGasFeeWithGasLimit(gasLimit);
const gasZRC20Contract = new ethers.Contract(gasZRC20, ZRC20ABI.abi, signer);
const gasFeeTransfer = await gasZRC20Contract.transfer(
const gasFeeApprove = await gasZRC20Contract.approve(
args.contract,
gasZRC20 == args.zrc20 ? gasFee.add(amount) : gasFee,
txOptions
);
await gasFeeTransfer.wait();
await gasFeeApprove.wait();

if (gasZRC20 !== args.zrc20) {
const targetTokenTransfer = await zrc20.transfer(
const targetTokenApprove = await zrc20.approve(
args.contract,
gasFee.add(amount),
txOptions
);
await targetTokenTransfer.wait();
await targetTokenApprove.wait();
}

const factory = (await hre.ethers.getContractFactory(args.name)) as any;
Expand Down

0 comments on commit b6a8ca3

Please sign in to comment.