mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
46 lines
1.8 KiB
Solidity
46 lines
1.8 KiB
Solidity
|
pragma solidity ^0.7.0;
|
||
|
|
||
|
import { TokenInterface } from "./interfaces.sol";
|
||
|
import { Stores } from "./stores.sol";
|
||
|
import { DSMath } from "./math.sol";
|
||
|
|
||
|
abstract contract Basic is DSMath, Stores {
|
||
|
|
||
|
function convert18ToDec(uint _dec, uint256 _amt) internal pure returns (uint256 amt) {
|
||
|
amt = (_amt / 10 ** (18 - _dec));
|
||
|
}
|
||
|
|
||
|
function convertTo18(uint _dec, uint256 _amt) internal pure returns (uint256 amt) {
|
||
|
amt = mul(_amt, 10 ** (18 - _dec));
|
||
|
}
|
||
|
|
||
|
function getTokenBal(TokenInterface token) internal view returns(uint _amt) {
|
||
|
_amt = address(token) == maticAddr ? address(this).balance : token.balanceOf(address(this));
|
||
|
}
|
||
|
|
||
|
function getTokensDec(TokenInterface buyAddr, TokenInterface sellAddr) internal view returns(uint buyDec, uint sellDec) {
|
||
|
buyDec = address(buyAddr) == maticAddr ? 18 : buyAddr.decimals();
|
||
|
sellDec = address(sellAddr) == maticAddr ? 18 : sellAddr.decimals();
|
||
|
}
|
||
|
|
||
|
function encodeEvent(string memory eventName, bytes memory eventParam) internal pure returns (bytes memory) {
|
||
|
return abi.encode(eventName, eventParam);
|
||
|
}
|
||
|
|
||
|
function changeMaticAddress(address buy, address sell) internal pure returns(TokenInterface _buy, TokenInterface _sell){
|
||
|
_buy = buy == maticAddr ? TokenInterface(wmaticAddr) : TokenInterface(buy);
|
||
|
_sell = sell == maticAddr ? TokenInterface(wmaticAddr) : TokenInterface(sell);
|
||
|
}
|
||
|
|
||
|
function convertMaticToWmatic(bool isMatic, TokenInterface token, uint amount) internal {
|
||
|
if(isMatic) token.deposit{value: amount}();
|
||
|
}
|
||
|
|
||
|
function convertWmaticToMatic(bool isMatic, TokenInterface token, uint amount) internal {
|
||
|
if(isMatic) {
|
||
|
token.approve(address(token), amount);
|
||
|
token.withdraw(amount);
|
||
|
}
|
||
|
}
|
||
|
}
|