dsa-connectors/contracts/mainnet/connectors/1proto/helpers.sol

32 lines
1.2 KiB
Solidity
Raw Normal View History

2021-03-21 09:13:05 +00:00
pragma solidity ^0.7.0;
import { TokenInterface } from "../../common/interfaces.sol";
import { DSMath } from "../../common/math.sol";
import { Basic } from "../../common/basic.sol";
2021-03-21 13:40:37 +00:00
import { TokenInterface, OneProtoInterface } from "./interface.sol";
2021-03-21 09:13:05 +00:00
abstract contract Helpers is DSMath, Basic {
/**
2021-03-21 13:40:37 +00:00
* @dev 1proto Address
2021-03-21 09:13:05 +00:00
*/
2021-03-21 13:40:37 +00:00
OneProtoInterface constant internal oneProto = OneProtoInterface(0x50FDA034C0Ce7a8f7EFDAebDA7Aa7cA21CC1267e);
2021-03-21 09:13:05 +00:00
function getSlippageAmt(
TokenInterface _buyAddr,
TokenInterface _sellAddr,
uint _sellAmt,
uint unitAmt
) internal view returns(uint _slippageAmt) {
(uint _buyDec, uint _sellDec) = getTokensDec(_buyAddr, _sellAddr);
uint _sellAmt18 = convertTo18(_sellDec, _sellAmt);
_slippageAmt = convert18ToDec(_buyDec, wmul(unitAmt, _sellAmt18));
}
function convertToTokenInterface(address[] memory tokens) internal pure returns(TokenInterface[] memory) {
TokenInterface[] memory _tokens = new TokenInterface[](tokens.length);
for (uint i = 0; i < tokens.length; i++) {
_tokens[i] = TokenInterface(tokens[i]);
}
return _tokens;
}
}