-
Notifications
You must be signed in to change notification settings - Fork 1
/
GSushiswapExchange.sol
58 lines (53 loc) · 2.68 KB
/
GSushiswapExchange.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.6.0;
import { GExchange } from "./GExchange.sol";
import { G } from "./G.sol";
import { SushiswapExchangeAbstraction } from "./modules/SushiswapExchangeAbstraction.sol";
/**
* @notice This contract implements the GExchange interface routing token
* conversions via Sushiswap.
*/
contract GSushiswapExchange is GExchange
{
/**
* @notice Computes the amount of tokens to be received upon conversion.
* @param _from The contract address of the ERC-20 token to convert from.
* @param _to The contract address of the ERC-20 token to convert to.
* @param _inputAmount The amount of the _from token to be provided (may be 0).
* @return _outputAmount The amount of the _to token to be received (may be 0).
*/
function calcConversionOutputFromInput(address _from, address _to, uint256 _inputAmount) public view override returns (uint256 _outputAmount)
{
return SushiswapExchangeAbstraction._calcConversionOutputFromInput(_from, _to, _inputAmount);
}
/**
* @notice Computes the amount of tokens to be provided upon conversion.
* @param _from The contract address of the ERC-20 token to convert from.
* @param _to The contract address of the ERC-20 token to convert to.
* @param _outputAmount The amount of the _to token to be received (may be 0).
* @return _inputAmount The amount of the _from token to be provided (may be 0).
*/
function calcConversionInputFromOutput(address _from, address _to, uint256 _outputAmount) public view override returns (uint256 _inputAmount)
{
return SushiswapExchangeAbstraction._calcConversionInputFromOutput(_from, _to, _outputAmount);
}
/**
* @notice Converts a given token amount to another token, as long as it
* meets the minimum taken amount. Amounts are debited from and
* and credited to the caller contract. It may fail if the
* minimum output amount cannot be met.
* @param _from The contract address of the ERC-20 token to convert from.
* @param _to The contract address of the ERC-20 token to convert to.
* @param _inputAmount The amount of the _from token to be provided (may be 0).
* @param _minOutputAmount The minimum amount of the _to token to be received (may be 0).
* @return _outputAmount The amount of the _to token received (may be 0).
*/
function convertFunds(address _from, address _to, uint256 _inputAmount, uint256 _minOutputAmount) public override returns (uint256 _outputAmount)
{
address _sender = msg.sender;
G.pullFunds(_from, _sender, _inputAmount);
_outputAmount = SushiswapExchangeAbstraction._convertFunds(_from, _to, _inputAmount, _minOutputAmount);
G.pushFunds(_to, _sender, _outputAmount);
return _outputAmount;
}
}