Merge pull request #239 from Instadapp/automation-connector

Insta Aave Automation connector
This commit is contained in:
Thrilok kumar 2022-08-04 23:20:15 +05:30 committed by GitHub
commit 1ae4b5f9ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 240 additions and 0 deletions

View File

@ -0,0 +1,11 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
contract Events {
event LogCancelAutomation();
event LogSubmitAutomation(uint256 safeHF, uint256 thresholdHF);
event LogUpdateAutomation(uint256 safeHF, uint256 thresholdHF);
}

View File

@ -0,0 +1,25 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
interface InstaAaveAutomation {
function submitAutomationRequest(
uint256 safeHealthFactor,
uint256 thresholdHealthFactor
) external;
function cancelAutomationRequest() external;
function updateAutomation(
uint256 safeHealthFactor,
uint256 thresholdHealthFactor
) external;
}
interface AccountInterface {
function enable(address) external;
function disable(address) external;
function isAuth(address) external view returns (bool);
}

View File

@ -0,0 +1,84 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
/**
* @title InstaAutomation
* @dev Insta-Aave-v3-Automation
*/
import "./events.sol";
import "./interfaces.sol";
abstract contract Resolver is Events {
InstaAaveAutomation internal immutable automation =
InstaAaveAutomation(0x08c1c01be430C9381AD2794412C3E940254CD97c);
function submitAutomationRequest(
uint256 safeHealthFactor,
uint256 thresholdHealthFactor
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
bool isAuth = AccountInterface(address(this)).isAuth(
address(automation)
);
if (!isAuth)
AccountInterface(address(this)).enable(address(automation));
automation.submitAutomationRequest(
safeHealthFactor,
thresholdHealthFactor
);
(_eventName, _eventParam) = (
"LogSubmitAutomation(uint256,uint256)",
abi.encode(safeHealthFactor, thresholdHealthFactor)
);
}
function cancelAutomationRequest()
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
automation.cancelAutomationRequest();
bool isAuth = AccountInterface(address(this)).isAuth(
address(automation)
);
if (isAuth)
AccountInterface(address(this)).disable(address(automation));
(_eventName, _eventParam) = ("LogCancelAutomation()", "0x");
}
function updateAutomationRequest(
uint256 safeHealthFactor,
uint256 thresholdHealthFactor
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
automation.cancelAutomationRequest();
automation.submitAutomationRequest(
safeHealthFactor,
thresholdHealthFactor
);
(_eventName, _eventParam) = (
"LogUpdateAutomation(uint256,uint256)",
abi.encode(safeHealthFactor, thresholdHealthFactor)
);
}
}
contract ConnectV2InstaAaveV3AutomationAvalanche is Resolver {
string public constant name = "Insta-Aave-V3-Automation-v1";
}

View File

@ -0,0 +1,11 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
contract Events {
event LogCancelAutomation();
event LogSubmitAutomation(uint256 safeHF, uint256 thresholdHF);
event LogUpdateAutomation(uint256 safeHF, uint256 thresholdHF);
}

View File

@ -0,0 +1,25 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
interface InstaAaveAutomation {
function submitAutomationRequest(
uint256 safeHealthFactor,
uint256 thresholdHealthFactor
) external;
function cancelAutomationRequest() external;
function updateAutomation(
uint256 safeHealthFactor,
uint256 thresholdHealthFactor
) external;
}
interface AccountInterface {
function enable(address) external;
function disable(address) external;
function isAuth(address) external view returns (bool);
}

View File

@ -0,0 +1,84 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
/**
* @title InstaAutomation
* @dev Insta-Aave-v3-Automation
*/
import "./events.sol";
import "./interfaces.sol";
abstract contract Resolver is Events {
InstaAaveAutomation internal immutable automation =
InstaAaveAutomation(0x3cF499Dbd2aBB6505f48Db27a9871523A38e6e2C);
function submitAutomationRequest(
uint256 safeHealthFactor,
uint256 thresholdHealthFactor
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
bool isAuth = AccountInterface(address(this)).isAuth(
address(automation)
);
if (!isAuth)
AccountInterface(address(this)).enable(address(automation));
automation.submitAutomationRequest(
safeHealthFactor,
thresholdHealthFactor
);
(_eventName, _eventParam) = (
"LogSubmitAutomation(uint256,uint256)",
abi.encode(safeHealthFactor, thresholdHealthFactor)
);
}
function cancelAutomationRequest()
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
automation.cancelAutomationRequest();
bool isAuth = AccountInterface(address(this)).isAuth(
address(automation)
);
if (isAuth)
AccountInterface(address(this)).disable(address(automation));
(_eventName, _eventParam) = ("LogCancelAutomation()", "0x");
}
function updateAutomationRequest(
uint256 safeHealthFactor,
uint256 thresholdHealthFactor
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
automation.cancelAutomationRequest();
automation.submitAutomationRequest(
safeHealthFactor,
thresholdHealthFactor
);
(_eventName, _eventParam) = (
"LogUpdateAutomation(uint256,uint256)",
abi.encode(safeHealthFactor, thresholdHealthFactor)
);
}
}
contract ConnectV2InstaAaveV3AutomationPolygon is Resolver {
string public constant name = "Insta-Aave-V3-Automation-v1";
}