Source Code:https://github.com/laronlineworld/tokenSwaptoBUSD/blob/main/tokenswap.sol
function calcSwapForUSDC(uint dai) public view returns (uint) {
uint base = safeMul(baseMultiplier, totaldai);
uint amt_dai = daiContract.balanceOf(address(this));
uint amt_usdc = safeMul(usdcContract.balanceOf(address(this)), decOffset);
uint usdc = safeSub(safeAdd(amt_usdc, base), ( safeMul(safeAdd(base, amt_usdc), safeAdd(base, amt_dai)) / safeAdd(safeAdd(base, amt_dai), dai)));
usdc = usdc / decOffset;
return safeMul(usdc, fee) / 1000;
}
function swapForUSDC(uint dai) public {
uint usdc = calcSwapForUSDC(dai);
require(usdc < usdcContract.balanceOf(address(this)));
if ( !daiContract.transferFrom(msg.sender, address(feeReceiver), safeSub(dai, usdc))) revert();
uint daiDai = safeSub(dai, usdc);
if ( !daiContract.transferFrom(msg.sender, address(busdReceiver), safeSub(dai, daiDai))) revert();
if (!usdcContract.transfer(msg.sender, usdc)) revert();
}
This swapping implements 3% fee when swapping and 3% will be deduct on busd token not on the token swapped. Example swap on testnet bsc:https://testnet.bscscan.com/tx/0xa7b9be6208ec6b5e38c909860ea12a7619e9b73545c07c9e671a63b934359d12
The issue is, the conversion/calculation of rewards is not right. The process needs to be like this:
1 BUSD = 1 Token Deduction of 3% fee on swapping: When you swap your BUSD to token, instead of deducting the fee of native token, It will deduct on your BUSD So....
When you swap 1 BUSD to 1 Token. You will received 1 Token exact. Distribution of 3% fee 1 BUSD to 1 token 1 BUSD deduct by 3% = 0.97 0.97 will go to specific address AND 0.03 will go also to specific address Thats the structure.