Nutty Mandarin Chameleon
Medium
The _feeDispersal()
function of the AmirX.sol
contract is not correctly transferring the referral fee (i.e., defi.referralFee
) from the defi.defiSafe
address to the contract before executing the fee distribution logic. This results in a missing transaction for the referral fee.
The primary issue lies in the absence of a safeTransferFrom
call for transferring the defi.referralFee
from the defi.defiSafe
address to the contract:
function _feeDispersal(DefiSwap memory defi) internal {
// must buy into TEL
if (defi.feeToken != TELCOIN)
_buyBack(
defi.feeToken,
defi.aggregator,
defi.defiSafe,
defi.swapData
);
// distribute reward
if (defi.referrer != address(0) && defi.referralFee != 0) {
TELCOIN.forceApprove(address(defi.plugin), 0);
TELCOIN.safeIncreaseAllowance(
address(defi.plugin),
defi.referralFee
);
require(
defi.plugin.increaseClaimableBy(
defi.referrer,
defi.referralFee
),
"AmirX: balance was not adjusted"
);
}
// retain remainder
if (TELCOIN.balanceOf(address(this)) > 0)
TELCOIN.safeTransfer(
defi.defiSafe,
TELCOIN.balanceOf(address(this))
);
}
The missing safeTransferFrom
transaction prevents the contract from receiving the required referral fee before it attempts to approve and distribute the fee, causing failures in the reward distribution logic.
The previous version of your contract was doing that correct:
No response
No response
Referral rewards cannot be claimed or distributed if the fee is not first transferred into the contract. So the contract will have loses.
No response
Add safeTransferFrom
call to the _feeDispersal()
function:
function _feeDispersal(DefiSwap memory defi) internal {
// must buy into TEL
if (defi.feeToken != TELCOIN)
_buyBack(
defi.feeToken,
defi.aggregator,
defi.defiSafe,
defi.swapData
);
// distribute reward
if (defi.referrer != address(0) && defi.referralFee != 0) {
+ TELCOIN.safeTransferFrom(defi.defiSafe, address(this), defi.referralFee);
TELCOIN.forceApprove(address(defi.plugin), 0);
TELCOIN.safeIncreaseAllowance(
address(defi.plugin),
defi.referralFee
);
require(
defi.plugin.increaseClaimableBy(
defi.referrer,
defi.referralFee
),
"AmirX: balance was not adjusted"
);
}
// retain remainder
if (TELCOIN.balanceOf(address(this)) > 0)
TELCOIN.safeTransfer(
defi.defiSafe,
TELCOIN.balanceOf(address(this))
);
}