pragma solidity ^0.5.0; contract feeApplicator { address[] public coins mapping(address => mapping(address => address[]) ) public pairsToShells mapping(address => mapping(address => uint256) ) public shells constructor () public { } function addShell (address[] memory coins) public { Shell shell = new Shell(coins); for (uint8 i = 0; i < coins.length; i++) { for (uint j = i + 1; j < coins.length; j++){ pairsToShells[coins[i]][coins[j]].push(shell) pairsToShells[coins[j]][coins[i]].push(shell) } shells[shell][coins[i]] = 0 } } function swap(ERC20 origin, ERC20 target, uint256 originInput) public { address[] storage shells = pairsToShells[origin][target]; uint256[shells.length] fees; uint256 originSupply = origin.balanceOf(address(this)); uint256 targetSupply = target.balanceOf(address(this)); uint256 numerator = originInput.mul(targetSupply).mul(10000); uint256 denominator = originSupply.add(originInput).mul(9975); uint256 targetOutput = numerator.div(denominator); uint256 fee = originInput.sub(targetOutput) for (uint8 i = 0; i < shells.length; i++) { balance = shells[i][origin] inputPercentile = shells[i][origin].div(originInput) outputPercentile = shells[i][target].div(targetOutput) shells[i][origin].sub(originInput.mul(inputPercentile)) shells[i][target].add(targetOutput.mul(outputPercentile)) } origin.transferFrom(msg.sender, address(this), originInput) target.transfer(msg.sender, targetOutput) } }
0.4.18