Skip to content

Commit

Permalink
Merge pull request #21 from ripio/refactor
Browse files Browse the repository at this point in the history
refactor
  • Loading branch information
Agustin Aguilar authored Aug 13, 2019
2 parents c266471 + 8af9658 commit 31f743d
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions contracts/ConverterRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract ConverterRamp is Ownable {
);

/// converter using token converter
convertSafe(_converter, _loanManagerAddress, _fromToken, address(token), amount);
convertSafe(_converter, _fromToken, address(token), amount);

/// pay loan
DebtEngine debtEngine = DebtEngine(_debtEngineAddress);
Expand Down Expand Up @@ -99,7 +99,10 @@ contract ConverterRamp is Ownable {
);

/// convert using token converter
convertSafe(_converter, _loanManagerAddress, _fromToken, address(token), amount);
(uint256 tokenCost) = convertSafe(_converter, _fromToken, address(token), amount);

/// approve token to loan manager
require(token.safeApprove(_loanManagerAddress, tokenCost), "Error approving lend token transfer");

uint256 prevTokenBalance = token.balanceOf(address(this));

Expand Down Expand Up @@ -139,24 +142,25 @@ contract ConverterRamp is Ownable {
/// @dev orchestrator between token->token, eth->token
function convertSafe(
address _converter,
address _loanManagerAddress,
address _fromToken,
address _token,
uint256 _amount
) internal {
) internal returns (uint256) {

(uint256 tokenCost, uint256 etherCost) = getCost(_amount, _converter, _fromToken, address(_token));
if (_fromToken == ETH_ADDRESS) {
ethConvertSafe(_converter, _fromToken, address(_token), _amount, tokenCost, etherCost);
return etherCost;
} else {
tokenConvertSafe(_converter, _loanManagerAddress, _fromToken, address(_token), _amount, tokenCost, etherCost);
tokenConvertSafe(_converter, _fromToken, address(_token), _amount, tokenCost, etherCost);
return tokenCost;
}
}

/// @dev not trusting the converter, validates all convertions using the token contract.
/// Token convertions
function tokenConvertSafe(
address _converter,
address _loanManagerAddress,
address _fromTokenAddress,
address _toTokenAddress,
uint256 _amount,
Expand Down Expand Up @@ -186,9 +190,6 @@ contract ConverterRamp is Ownable {
/// if we are converting from a token, remove the approve
require(fromToken.safeApprove(address(tokenConverter), 0), "Error removing token approve");

/// approve token to loan manager
require(toToken.safeApprove(_loanManagerAddress, _tokenCost), "Error approving lend token transfer");

}

/// @dev not trusting the converter, validates all convertions using the token contract.
Expand Down

0 comments on commit 31f743d

Please sign in to comment.