Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions contracts/proxy/LiqualityRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,55 @@ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./interfaces/ILiqualityRouter.sol";
import "./interfaces/ILiqualityProxy.sol";
import "./LibTransfer.sol";
import "../referrals/interfaces/IReferralRegistry.sol";

contract LiqualityRouter is ILiqualityRouter {
using LibTransfer for address;
using SafeERC20 for IERC20;

ILiqualityProxy public liqualityProxy;
IReferralRegistry public referralRegistry;

constructor(address _liqualityProxy) {
liqualityProxy = ILiqualityProxy(_liqualityProxy);
}

function route(
function routeWithReferral(
address target,
address tokenFrom,
address referrer,
uint256 amount,
bytes calldata data,
FeeData[] calldata fees
) external payable {
uint256 totalFee = 0;
address user = msg.sender;
// handle referrals
Referral memory referral = referralRegistry.getReferral(user);
Comment on lines +30 to +31
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think referralRegistry was ever initialized, at what point did you equate referralRegistry to the Referral smart contract address?

if (referral.referrer != address(0x0)) {
referralRegistry.registerReferral(referrer, user);
}
_route(target, user, tokenFrom, amount, data, fees);
}

function route(
address target,
address tokenFrom,
uint256 amount,
bytes calldata data,
FeeData[] calldata fees
) external payable {
_route(target, msg.sender, tokenFrom, amount, data, fees);
}

function _route(
address target,
address from,
address tokenFrom,
uint256 amount,
bytes calldata data,
FeeData[] calldata fees
) internal {
uint256 totalFee = 0;
// handle ETH fees
if (tokenFrom == address(0)) {
for (uint256 i = 0; i < fees.length; i++) {
Expand All @@ -35,9 +63,9 @@ contract LiqualityRouter is ILiqualityRouter {
}
// handle ERC20 fees
else {
IERC20(tokenFrom).safeTransferFrom(user, address(liqualityProxy), amount);
IERC20(tokenFrom).safeTransferFrom(from, address(liqualityProxy), amount);
for (uint256 i = 0; i < fees.length; i++) {
IERC20(tokenFrom).safeTransferFrom(user, fees[i].account, fees[i].fee);
IERC20(tokenFrom).safeTransferFrom(from, fees[i].account, fees[i].fee);
}
}

Expand Down