Skip to content

Commit

Permalink
Adjusting contract to work with approve address
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoavf committed Jun 30, 2023
1 parent c6fa8c8 commit 287080c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
26 changes: 15 additions & 11 deletions contracts/bridges/ZeroX/ZeroXBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@ pragma solidity ^0.8.6;
import "@uniswap/v2-periphery/contracts/interfaces/IERC20.sol";
import "./interfaces/ZeroXERC20.sol";

struct ZeroXParams {
address fromToken;
address toToken;
uint256 amountInPercentage;
uint256 minAmountOut;
Transformation[] transformations;
}

contract ZeroXBridge {
event DEFIBASKET_ZEROX_SWAP(uint256 receivedAmount);

function swap(
address zeroXaddress,
address fromToken,
address toToken,
uint256 amountInPercentage,
uint256 minAmountOut,
Transformation[] memory transformations
address approveAddress,
ZeroXParams calldata params
) external {
uint256 amount = IERC20(fromToken).balanceOf(address(this))*amountInPercentage/100000;
IERC20(fromToken).approve(zeroXaddress, amount);
uint256 amount = IERC20(params.fromToken).balanceOf(address(this))*params.amountInPercentage/100000;
IERC20(params.fromToken).approve(approveAddress, amount);

ZeroXERC20 zerox = ZeroXERC20(zeroXaddress);

uint256 receivedAmount = zerox.transformERC20(
fromToken,
toToken,
params.fromToken,
params.toToken,
amount,
minAmountOut,
transformations
params.minAmountOut,
params.transformations
);

emit DEFIBASKET_ZEROX_SWAP(receivedAmount);
Expand Down
15 changes: 8 additions & 7 deletions test/ZeroXBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ describe("ZeroX", function(){
});

console.log(decodedFunctionCall);
console.log('zz', decodedFunctionCall.args[4]);


// Set bridges addresses
var _bridgeAddresses = [wmaticBridge.address, zeroXBridge.address];
Expand All @@ -60,11 +58,14 @@ describe("ZeroX", function(){
wmaticBridge.interface.encodeFunctionData("wrap", [100000]),
zeroXBridge.interface.encodeFunctionData("swap", [
body.to,
decodedFunctionCall.args[0],
decodedFunctionCall.args[1],
"100000",
"1",
decodedFunctionCall.args[4]
body.allowanceTarget,
[
decodedFunctionCall.args[0],
decodedFunctionCall.args[1],
"100000",
"1",
decodedFunctionCall.args[4],
]
])
];

Expand Down

0 comments on commit 287080c

Please sign in to comment.