mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
changed flashLoanFee to flashLoanFees[], removed migrateCompound function, removed checks for repeated tokens from getSupplyAmounts and getBorrowAmounts
This commit is contained in:
parent
8e74f75862
commit
b14f886365
|
@ -79,15 +79,6 @@ contract CompoundHelper is Helpers {
|
||||||
data.borrowCtokensAddr = new address[](_importInputData.borrowIds.length);
|
data.borrowCtokensAddr = new address[](_importInputData.borrowIds.length);
|
||||||
data.borrowAmts = new uint[](_importInputData.borrowIds.length);
|
data.borrowAmts = new uint[](_importInputData.borrowIds.length);
|
||||||
|
|
||||||
// check for repeated tokens
|
|
||||||
for (uint i = 0; i < _importInputData.borrowIds.length; i++) {
|
|
||||||
bytes32 i_hash = keccak256(abi.encode(_importInputData.borrowIds[i]));
|
|
||||||
for (uint j = i + 1; j < _importInputData.borrowIds.length; j++) {
|
|
||||||
bytes32 j_hash = keccak256(abi.encode(_importInputData.borrowIds[j]));
|
|
||||||
require(i_hash != j_hash, "token-repeated");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// populate the arrays with borrow tokens, cToken addresses and instances, and borrow amounts
|
// populate the arrays with borrow tokens, cToken addresses and instances, and borrow amounts
|
||||||
for (uint i = 0; i < _importInputData.borrowIds.length; i++) {
|
for (uint i = 0; i < _importInputData.borrowIds.length; i++) {
|
||||||
(address _token, address _cToken) = compMapping.getMapping(_importInputData.borrowIds[i]);
|
(address _token, address _cToken) = compMapping.getMapping(_importInputData.borrowIds[i]);
|
||||||
|
@ -128,15 +119,6 @@ contract CompoundHelper is Helpers {
|
||||||
data.supplyCtokensAddr = new address[](_importInputData.supplyIds.length);
|
data.supplyCtokensAddr = new address[](_importInputData.supplyIds.length);
|
||||||
data.supplyAmts = new uint[](_importInputData.supplyIds.length);
|
data.supplyAmts = new uint[](_importInputData.supplyIds.length);
|
||||||
|
|
||||||
// check for repeated tokens
|
|
||||||
for (uint i = 0; i < _importInputData.supplyIds.length; i++) {
|
|
||||||
bytes32 i_hash = keccak256(abi.encode(_importInputData.supplyIds[i]));
|
|
||||||
for (uint j = i + 1; j < _importInputData.supplyIds.length; j++) {
|
|
||||||
bytes32 j_hash = keccak256(abi.encode(_importInputData.supplyIds[j]));
|
|
||||||
require(i_hash != j_hash, "token-repeated");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// populate arrays with supply data (supply tokens address, cToken addresses, cToken instances and supply amounts)
|
// populate arrays with supply data (supply tokens address, cToken addresses, cToken instances and supply amounts)
|
||||||
for (uint i = 0; i < _importInputData.supplyIds.length; i++) {
|
for (uint i = 0; i < _importInputData.supplyIds.length; i++) {
|
||||||
(address _token, address _cToken) = compMapping.getMapping(_importInputData.supplyIds[i]);
|
(address _token, address _cToken) = compMapping.getMapping(_importInputData.supplyIds[i]);
|
||||||
|
@ -172,7 +154,10 @@ contract CompoundHelper is Helpers {
|
||||||
cEth.repayBorrowBehalf{value: _borrowAmts[i]}(_userAccount);
|
cEth.repayBorrowBehalf{value: _borrowAmts[i]}(_userAccount);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
require(_cTokenContracts[i].repayBorrowBehalf(_userAccount, _borrowAmts[i]) == 0, "repayOnBehalf-failed");
|
require(_cTokenContracts[i].repayBorrowBehalf(
|
||||||
|
_userAccount,
|
||||||
|
_borrowAmts[i]
|
||||||
|
) == 0, "repayOnBehalf-failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,7 +177,11 @@ contract CompoundHelper is Helpers {
|
||||||
) internal {
|
) internal {
|
||||||
for(uint i = 0; i < _cTokenContracts.length; i++) {
|
for(uint i = 0; i < _cTokenContracts.length; i++) {
|
||||||
if(_amts[i] > 0) {
|
if(_amts[i] > 0) {
|
||||||
require(_cTokenContracts[i].transferFrom(_userAccount, address(this), _amts[i]), "ctoken-transfer-failed-allowance?");
|
require(_cTokenContracts[i].transferFrom(
|
||||||
|
_userAccount,
|
||||||
|
address(this),
|
||||||
|
_amts[i]
|
||||||
|
), "ctoken-transfer-failed-allowance?");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,16 +191,20 @@ contract CompoundHelper is Helpers {
|
||||||
* @dev actually borrow some extra amount than the original position to cover the flash loan fee
|
* @dev actually borrow some extra amount than the original position to cover the flash loan fee
|
||||||
* @param _cTokenContracts array containing all interfaces to the cToken contracts in which the user has debt positions
|
* @param _cTokenContracts array containing all interfaces to the cToken contracts in which the user has debt positions
|
||||||
* @param _amts array containing the amounts the user had borrowed originally from Compound plus the flash loan fee
|
* @param _amts array containing the amounts the user had borrowed originally from Compound plus the flash loan fee
|
||||||
* @param _flashLoanFee flash loan fee (in percentage and scaled up to 10**2)
|
* @param _flashLoanFees flash loan fee (in percentage and scaled up to 10**2)
|
||||||
*/
|
*/
|
||||||
function _borrowDebtPosition(
|
function _borrowDebtPosition(
|
||||||
CTokenInterface[] memory _cTokenContracts,
|
CTokenInterface[] memory _cTokenContracts,
|
||||||
uint256[] memory _amts,
|
uint256[] memory _amts,
|
||||||
uint256 _flashLoanFee
|
uint256[] memory _flashLoanFees
|
||||||
) internal {
|
) internal {
|
||||||
for (uint i = 0; i < _cTokenContracts.length; i++) {
|
for (uint i = 0; i < _cTokenContracts.length; i++) {
|
||||||
if (_amts[i] > 0) {
|
if (_amts[i] > 0) {
|
||||||
require(_cTokenContracts[i].borrow(add(_amts[i], mul(_amts[i], mul(_flashLoanFee, 10**14)))) == 0, "borrow-failed-collateral?");
|
require(_cTokenContracts[i].borrow(
|
||||||
|
add(
|
||||||
|
_amts[i],
|
||||||
|
_flashLoanFees[i]
|
||||||
|
)) == 0, "borrow-failed-collateral?");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,11 @@ contract CompoundImportResolver is CompoundHelper {
|
||||||
* @notice this function performs the import of user's Compound positions into its DSA
|
* @notice this function performs the import of user's Compound positions into its DSA
|
||||||
* @dev called internally by the importCompound and migrateCompound functions
|
* @dev called internally by the importCompound and migrateCompound functions
|
||||||
* @param _importInputData the struct containing borrowIds of the users borrowed tokens
|
* @param _importInputData the struct containing borrowIds of the users borrowed tokens
|
||||||
* @param _flashLoanFee flash loan fee
|
* @param _flashLoanFees list of flash loan fees
|
||||||
*/
|
*/
|
||||||
function _importCompound(
|
function _importCompound(
|
||||||
ImportInputData memory _importInputData,
|
ImportInputData memory _importInputData,
|
||||||
uint256 _flashLoanFee
|
uint256[] memory _flashLoanFees
|
||||||
) internal returns (string memory _eventName, bytes memory _eventParam) {
|
) internal returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
require(AccountInterface(address(this)).isAuth(_importInputData.userAccount), "user-account-not-auth");
|
require(AccountInterface(address(this)).isAuth(_importInputData.userAccount), "user-account-not-auth");
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ contract CompoundImportResolver is CompoundHelper {
|
||||||
_transferTokensToDsa(_importInputData.userAccount, data.supplyCtokens, data.supplyAmts);
|
_transferTokensToDsa(_importInputData.userAccount, data.supplyCtokens, data.supplyAmts);
|
||||||
|
|
||||||
// borrow the earlier position from Compound with flash loan fee added
|
// borrow the earlier position from Compound with flash loan fee added
|
||||||
_borrowDebtPosition(data.borrowCtokens, data.borrowAmts, _flashLoanFee);
|
_borrowDebtPosition(data.borrowCtokens, data.borrowAmts, _flashLoanFees);
|
||||||
|
|
||||||
_eventName = "LogCompoundImport(address,address[],string[],string[],uint256[],uint256[])";
|
_eventName = "LogCompoundImport(address,address[],string[],string[],uint256[],uint256[])";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
|
@ -65,13 +65,13 @@ contract CompoundImportResolver is CompoundHelper {
|
||||||
* @param _userAccount address of user whose position is to be imported to DSA
|
* @param _userAccount address of user whose position is to be imported to DSA
|
||||||
* @param _supplyIds Ids of all tokens the user has supplied to Compound
|
* @param _supplyIds Ids of all tokens the user has supplied to Compound
|
||||||
* @param _borrowIds Ids of all token borrowed by the user
|
* @param _borrowIds Ids of all token borrowed by the user
|
||||||
* @param _flashLoanFee flash loan fee (in percentage and scaled up to 10**2)
|
* @param _flashLoanFees list of flash loan fees
|
||||||
*/
|
*/
|
||||||
function importCompound(
|
function importCompound(
|
||||||
address _userAccount,
|
address _userAccount,
|
||||||
string[] memory _supplyIds,
|
string[] memory _supplyIds,
|
||||||
string[] memory _borrowIds,
|
string[] memory _borrowIds,
|
||||||
uint256 _flashLoanFee
|
uint256[] memory _flashLoanFees
|
||||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
ImportInputData memory inputData = ImportInputData({
|
ImportInputData memory inputData = ImportInputData({
|
||||||
userAccount: _userAccount,
|
userAccount: _userAccount,
|
||||||
|
@ -79,29 +79,9 @@ contract CompoundImportResolver is CompoundHelper {
|
||||||
borrowIds: _borrowIds
|
borrowIds: _borrowIds
|
||||||
});
|
});
|
||||||
|
|
||||||
(_eventName, _eventParam) = _importCompound(inputData, _flashLoanFee);
|
(_eventName, _eventParam) = _importCompound(inputData, _flashLoanFees);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @notice import msg.sender's Compound position (which is the user since this is a delegateCall)
|
|
||||||
* @dev internally calls _importContract to perform the actual import
|
|
||||||
* @param _supplyIds Ids of all tokens the user has supplied to Compound
|
|
||||||
* @param _borrowIds Ids of all token borrowed by the user
|
|
||||||
* @param _flashLoanFee flash loan fee (in percentage and scaled up to 10**2)
|
|
||||||
*/
|
|
||||||
function migrateCompound(
|
|
||||||
string[] memory _supplyIds,
|
|
||||||
string[] memory _borrowIds,
|
|
||||||
uint256 _flashLoanFee
|
|
||||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
|
||||||
ImportInputData memory inputData = ImportInputData({
|
|
||||||
userAccount: msg.sender,
|
|
||||||
supplyIds: _supplyIds,
|
|
||||||
borrowIds: _borrowIds
|
|
||||||
});
|
|
||||||
|
|
||||||
(_eventName, _eventParam) = _importCompound(inputData, _flashLoanFee);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contract ConnectV2CompoundImport is CompoundImportResolver {
|
contract ConnectV2CompoundImport is CompoundImportResolver {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user