mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
Single fee function
This commit is contained in:
parent
e111e80d82
commit
76352ca500
|
@ -1,6 +1,9 @@
|
||||||
pragma solidity ^0.6.0;
|
pragma solidity ^0.6.0;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||||
|
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
|
|
||||||
interface TokenInterface {
|
interface TokenInterface {
|
||||||
function approve(address, uint256) external;
|
function approve(address, uint256) external;
|
||||||
function transfer(address, uint) external;
|
function transfer(address, uint) external;
|
||||||
|
@ -255,6 +258,8 @@ contract DSMath {
|
||||||
|
|
||||||
contract Helpers is DSMath {
|
contract Helpers is DSMath {
|
||||||
|
|
||||||
|
using SafeERC20 for IERC20;
|
||||||
|
|
||||||
address payable constant feeCollector = 0xb1DC62EC38E6E3857a887210C38418E4A17Da5B2;
|
address payable constant feeCollector = 0xb1DC62EC38E6E3857a887210C38418E4A17Da5B2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -487,6 +492,14 @@ contract Helpers is DSMath {
|
||||||
amt = CTokenInterface(cToken).borrowBalanceCurrent(address(this));
|
amt = CTokenInterface(cToken).borrowBalanceCurrent(address(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function transferFees(address token, uint feeAmt) internal {
|
||||||
|
if (token == getEthAddr()) {
|
||||||
|
feeCollector.transfer(feeAmt);
|
||||||
|
} else {
|
||||||
|
IERC20(token).safeTransfer(feeCollector, feeAmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract CompoundHelpers is Helpers {
|
contract CompoundHelpers is Helpers {
|
||||||
|
@ -513,11 +526,7 @@ contract CompoundHelpers is Helpers {
|
||||||
uint _amt = add(amt, feeAmt);
|
uint _amt = add(amt, feeAmt);
|
||||||
|
|
||||||
require(CTokenInterface(cToken).borrow(_amt) == 0, "borrow-failed-collateral?");
|
require(CTokenInterface(cToken).borrow(_amt) == 0, "borrow-failed-collateral?");
|
||||||
if (token == getEthAddr()) {
|
transferFees(token, feeAmt);
|
||||||
feeCollector.transfer(feeAmt);
|
|
||||||
} else {
|
|
||||||
TokenInterface(token).transfer(feeCollector, feeAmt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return amt;
|
return amt;
|
||||||
}
|
}
|
||||||
|
@ -548,11 +557,10 @@ contract CompoundHelpers is Helpers {
|
||||||
TokenInterface tokenContract = TokenInterface(token);
|
TokenInterface tokenContract = TokenInterface(token);
|
||||||
tokenContract.approve(cToken, _amt);
|
tokenContract.approve(cToken, _amt);
|
||||||
require(CTokenInterface(cToken).mint(_amt) == 0, "deposit-failed");
|
require(CTokenInterface(cToken).mint(_amt) == 0, "deposit-failed");
|
||||||
tokenContract.transfer(feeCollector, feeAmt);
|
|
||||||
} else {
|
} else {
|
||||||
CETHInterface(cToken).mint.value(_amt)();
|
CETHInterface(cToken).mint.value(_amt)();
|
||||||
feeCollector.transfer(feeAmt);
|
|
||||||
}
|
}
|
||||||
|
transferFees(token, feeAmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -642,11 +650,7 @@ contract AaveV1Helpers is CompoundHelpers {
|
||||||
uint _amt = add(amt, feeAmt);
|
uint _amt = add(amt, feeAmt);
|
||||||
|
|
||||||
aave.borrow(token, _amt, borrowRateMode, getReferralCode());
|
aave.borrow(token, _amt, borrowRateMode, getReferralCode());
|
||||||
if (token == getEthAddr()) {
|
transferFees(token, feeAmt);
|
||||||
feeCollector.transfer(feeAmt);
|
|
||||||
} else {
|
|
||||||
TokenInterface(token).transfer(feeCollector, feeAmt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return amt;
|
return amt;
|
||||||
}
|
}
|
||||||
|
@ -690,13 +694,13 @@ contract AaveV1Helpers is CompoundHelpers {
|
||||||
bool isEth = token == getEthAddr();
|
bool isEth = token == getEthAddr();
|
||||||
if (isEth) {
|
if (isEth) {
|
||||||
ethAmt = _amt;
|
ethAmt = _amt;
|
||||||
feeCollector.transfer(feeAmt);
|
|
||||||
} else {
|
} else {
|
||||||
TokenInterface tokenContract = TokenInterface(token);
|
TokenInterface tokenContract = TokenInterface(token);
|
||||||
tokenContract.approve(address(aave), _amt);
|
tokenContract.approve(address(aave), _amt);
|
||||||
tokenContract.transfer(feeCollector, feeAmt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transferFees(token, feeAmt);
|
||||||
|
|
||||||
aave.deposit.value(ethAmt)(token, _amt, getReferralCode());
|
aave.deposit.value(ethAmt)(token, _amt, getReferralCode());
|
||||||
|
|
||||||
if (!getIsColl(aave, token))
|
if (!getIsColl(aave, token))
|
||||||
|
@ -808,11 +812,7 @@ contract AaveV2Helpers is AaveV1Helpers {
|
||||||
aave.borrow(_token, _amt, rateMode, getReferralCode(), address(this));
|
aave.borrow(_token, _amt, rateMode, getReferralCode(), address(this));
|
||||||
convertWethToEth(isEth, TokenInterface(_token), amt);
|
convertWethToEth(isEth, TokenInterface(_token), amt);
|
||||||
|
|
||||||
if (isEth) {
|
transferFees(token, feeAmt);
|
||||||
feeCollector.transfer(feeAmt);
|
|
||||||
} else {
|
|
||||||
TokenInterface(_token).transfer(feeCollector, feeAmt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return amt;
|
return amt;
|
||||||
}
|
}
|
||||||
|
@ -848,11 +848,7 @@ contract AaveV2Helpers is AaveV1Helpers {
|
||||||
address _token = isEth ? getWethAddr() : token;
|
address _token = isEth ? getWethAddr() : token;
|
||||||
TokenInterface tokenContract = TokenInterface(_token);
|
TokenInterface tokenContract = TokenInterface(_token);
|
||||||
|
|
||||||
if (isEth) {
|
transferFees(token, feeAmt);
|
||||||
feeCollector.transfer(feeAmt);
|
|
||||||
} else {
|
|
||||||
tokenContract.transfer(feeCollector, feeAmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
convertEthToWeth(isEth, tokenContract, _amt);
|
convertEthToWeth(isEth, tokenContract, _amt);
|
||||||
|
|
||||||
|
@ -990,7 +986,7 @@ contract MakerHelpers is AaveV2Helpers {
|
||||||
|
|
||||||
DaiJoinInterface(daiJoin).exit(address(this), _amt);
|
DaiJoinInterface(daiJoin).exit(address(this), _amt);
|
||||||
|
|
||||||
TokenInterface(getMcdDai()).transfer(feeCollector, feeAmt);
|
transferFees(getMcdDai(), feeAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _makerDeposit(uint vault, uint amt, uint fee) internal {
|
function _makerDeposit(uint vault, uint amt, uint fee) internal {
|
||||||
|
@ -1006,11 +1002,10 @@ contract MakerHelpers is AaveV2Helpers {
|
||||||
TokenJoinInterface tokenJoinContract = TokenJoinInterface(colAddr);
|
TokenJoinInterface tokenJoinContract = TokenJoinInterface(colAddr);
|
||||||
TokenInterface tokenContract = tokenJoinContract.gem();
|
TokenInterface tokenContract = tokenJoinContract.gem();
|
||||||
|
|
||||||
|
transferFees(address(tokenContract), feeAmt);
|
||||||
|
|
||||||
if (address(tokenContract) == getWethAddr()) {
|
if (address(tokenContract) == getWethAddr()) {
|
||||||
feeCollector.transfer(feeAmt);
|
|
||||||
tokenContract.deposit.value(amt)();
|
tokenContract.deposit.value(amt)();
|
||||||
} else {
|
|
||||||
tokenContract.transfer(feeCollector, feeAmt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenContract.approve(address(colAddr), amt);
|
tokenContract.approve(address(colAddr), amt);
|
||||||
|
|
1
package-lock.json
generated
1
package-lock.json
generated
|
@ -9871,7 +9871,6 @@
|
||||||
"integrity": "sha1-gewXhBRUkfLqqJVbMcBgSeB8Xn0=",
|
"integrity": "sha1-gewXhBRUkfLqqJVbMcBgSeB8Xn0=",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"bignumber.js": "bignumber.js@git+https://github.com/debris/bignumber.js.git#94d7146671b9719e00a09c29b01a691bc85048c2",
|
|
||||||
"crypto-js": "^3.1.4",
|
"crypto-js": "^3.1.4",
|
||||||
"utf8": "^2.1.1",
|
"utf8": "^2.1.1",
|
||||||
"xhr2": "*",
|
"xhr2": "*",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user