Skip to content

Instantly share code, notes, and snippets.

@alexon1234
Created April 28, 2021 21:32
Show Gist options
  • Save alexon1234/a2d3619fb3faa4e5676329f70bd565d3 to your computer and use it in GitHub Desktop.
Save alexon1234/a2d3619fb3faa4e5676329f70bd565d3 to your computer and use it in GitHub Desktop.
Swap fee not applied

In Pool.sol, we have the method swap In this method we are calculating the swap fee, but we do not apply it, so is basically like we don't charge anything.

// Designed to be called by a router, but can be called directly
    function swap(
        address base,
        address token,
        address member,
        bool toBase
    ) external returns (uint256 outputAmount) {
        // true
        if (toBase) {
            // 100
            uint256 _actualInput = getAddedAmount(token, token);
            outputAmount = iUTILS(UTILS()).calcSwapOutput(  
                _actualInput,                   
                mapToken_tokenAmount[token],    
                mapToken_baseAmount[token]      
            );

            uint256 _swapFee =
                iUTILS(UTILS()).calcSwapFee(
                    _actualInput,
                    mapToken_tokenAmount[token],
                    mapToken_baseAmount[token]
                );
            mapToken_tokenAmount[token] += _actualInput;  
            mapToken_baseAmount[token] -= outputAmount; 
            emit Swap(
                member,
                token,
                _actualInput,
                base,
                outputAmount,
                _swapFee
            );
            transferOut(base, outputAmount, member);
        } else {
            uint256 _actualInput = getAddedAmount(base, token);
            outputAmount = iUTILS(UTILS()).calcSwapOutput(
                _actualInput,
                mapToken_baseAmount[token],
                mapToken_tokenAmount[token]
            );
            uint256 _swapFee =
                iUTILS(UTILS()).calcSwapFee(
                    _actualInput,
                    mapToken_baseAmount[token],
                    mapToken_tokenAmount[token]
                );
            mapToken_baseAmount[token] += _actualInput;
            mapToken_tokenAmount[token] -= outputAmount;
            emit Swap(
                member,
                base,
                _actualInput,
                token,
                outputAmount,
                _swapFee
            );
            transferOut(token, outputAmount, member);
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment