mirror of
https://github.com/Instadapp/Gelato-automations.git
synced 2024-07-29 22:28:07 +00:00
refactored debt bridge smart contract, added comments and edited readme
This commit is contained in:
parent
57a48812a5
commit
0b8ef845d9
28
README.md
28
README.md
|
@ -6,7 +6,11 @@
|
|||
<img src="assets/instadapp_filled.svg" width="150px"/>
|
||||
<img src="assets/Gelato_Black.svg" width="150px"/></p>
|
||||
|
||||
This repo contains smart contract prototypes and mocks and a test suite showcasing how the InstaDapp DSA could use Gelato to automate the execution (or casting) of its Spells (connectors) based on arbitrary Conditions.
|
||||
This repo contains smart contracts, mocks and a test suite showcasing how InstaDapp DSAs and Gelato can work together to automate the execution (or casting) of Spells (connectors) based on arbitrary Conditions.
|
||||
|
||||
## Use Cases
|
||||
|
||||
### 1. Move DAI lending from DSR to Compound
|
||||
|
||||
For the first iteration, we started with a simple spell:
|
||||
**Move DAI lending from DSR to Compound.**
|
||||
|
@ -22,11 +26,13 @@ Furtheremore the following contracts were added to showcase the automation of th
|
|||
|
||||
- `ConnectGelato`: this is a Connector needed for the DSA to be able to submit Tasks to Gelato. In the test suite we unlock the DSA MultiSig Master account at 0xfCD22438AD6eD564a1C26151Df73F6B33B817B56, in order to be able to enable this Connector in our mainnet fork running on the local hardhat network instance.
|
||||
|
||||
To see for yourself check out the [contracts](./contracts) folder and make sure to check out `test/mv-DAI-DSR-Compound.test.js`, to see an end-to-end test showcasing the prototype. To do so follow the steps below:
|
||||
In this example, the DSA simply pre-deposits some ETH on Gelato to repay the executor for the transaction fees incurred from executing the task.
|
||||
|
||||
## Debt Bridge
|
||||
To see for yourself check out the [contracts](./contracts) folder and make sure to check out `test/mv-DAI-DSR-Compound.test.js`, to see an end-to-end test showcasing the prototype.
|
||||
|
||||
Debt Bridge is a financial process that aim to make the user position safer. InstaDapp DSA could use Gelato to automate this process.
|
||||
### 2. Debt Bridge - Refinance debt position from Maker to Compound based on changes in the ETH / USD price
|
||||
|
||||
Debt Bridge is a financial process that aims to make the user position safer. InstaDapp DSA and Gelato together can automate this process.
|
||||
|
||||
### Full Refinancing from Maker's Vault to Compound.
|
||||
|
||||
|
@ -34,11 +40,19 @@ Based on the [debt bridge](https://docs.instadapp.io/usecases/debt-bridge/) docu
|
|||
|
||||
- `ConditionMakerVaultIsSafe.sol`: determine if a specific vault is on an unsafe position.
|
||||
|
||||
- `ConnectGelatoDebtBridge.sol`: use Instamemory to assign values to the differents inputs needed by `ConnectMaker` and `ConnectCompound` like the amount of DAI to pay back, the amount of Ether to withdraw from Maker etc...
|
||||
- `ConnectGelatoDebtBridge.sol`: generates the required data which will be assigned to the different inputs needed by `ConnectMaker` and `ConnectCompound` by using InstaMemory. Examples are the amount of DAI to pay back or the amount of Ether to withdraw from Maker.
|
||||
|
||||
- `ConnectGelatoProviderPayment.sol`: will pay the Gelato provider (the Ethereum account paying the transaction).
|
||||
- `ConnectGelatoProviderPayment.sol`: makes sure part of the moved collateral is used to pay the Gelato provider for the incurred transaction fee. The Gelato Provider will in turn pay the executor who executed the task.
|
||||
|
||||
For understanding the entire process of a full refinancing, from the opening of the vault on maker to the execution of the refinancing on InstaDapp, take a look at `test/2_Full-Refinance-External-Provider.test.js` test.
|
||||
In this example, the executor will be refunded for the incurred transaction fees by subtracting the estimated gas costs from the collateral which is moved from Maker to Compound. This means the user does not have to pre pay in order to incentivize the execution of the task.
|
||||
|
||||
For understanding the entire process of a full refinancing, from the opening of the vault on maker to the execution of the refinancing on InstaDapp, take a look at `test/2_Full-Debt-Bridge-Maker-Compound.test.js` test.
|
||||
|
||||
## Known Bugs
|
||||
|
||||
Sometimes when running the `test/2_Full-Debt-Bridge-Maker-Compound.test.js` test, Hardhat will throw the folliwing error: `AssertionError: Expected event "LogExecSuccess" to be emitted, but it wasn't`. If this happens, just wait a few seconds and re-run the tests, eventually it should work.
|
||||
|
||||
## Run the tests
|
||||
|
||||
1. Clone this repo
|
||||
2. Put your Alchemy ID in .env
|
||||
|
|
|
@ -308,12 +308,14 @@ contract ConnectGelatoDebtBridgeFromMaker is MakerResolver {
|
|||
_priceOracle,
|
||||
_oraclePayload
|
||||
);
|
||||
setUint(600, wDaiDebtToMove); // flashloan borrow
|
||||
setUint(601, wDaiDebtToMove); // payback maker
|
||||
setUint(602, _add(wCollateralToMove, gasFeesPaidFromCol)); // withdraw maker
|
||||
setUint(603, wCollateralToMove); // deposit compound
|
||||
setUint(604, wDaiDebtToMove); // borrow compound
|
||||
setUint(605, gasFeesPaidFromCol); // pay the Gelato Provider (TO DO: unsafe)
|
||||
|
||||
_setInstaMemoryUints(
|
||||
wDaiDebtToMove,
|
||||
_add(wCollateralToMove, gasFeesPaidFromCol),
|
||||
wCollateralToMove,
|
||||
wDaiDebtToMove,
|
||||
gasFeesPaidFromCol
|
||||
);
|
||||
}
|
||||
|
||||
/// @notice Save in instaMemory the needed values for doing full refinancing between makerDAO and Compound.
|
||||
|
@ -329,12 +331,34 @@ contract ConnectGelatoDebtBridgeFromMaker is MakerResolver {
|
|||
uint256 paybackAmount = getMakerVaultDebt(_vaultID);
|
||||
uint256 collateralToWithdraw = getMakerVaultCollateralBalance(_vaultID);
|
||||
|
||||
setUint(600, paybackAmount);
|
||||
setUint(601, paybackAmount); // payback maker
|
||||
setUint(602, collateralToWithdraw); // withdraw maker
|
||||
setUint(603, _sub(collateralToWithdraw, fees)); // deposit compound
|
||||
setUint(604, paybackAmount); // borrow compound
|
||||
setUint(605, fees); // pay the provider
|
||||
_setInstaMemoryUints(
|
||||
paybackAmount,
|
||||
collateralToWithdraw,
|
||||
_sub(collateralToWithdraw, fees),
|
||||
paybackAmount,
|
||||
fees
|
||||
);
|
||||
}
|
||||
|
||||
/// @notice Internal function to store values in InstaMemory
|
||||
/// @param _makerDebtRepaymentAmount payback maker && flashloan borrow amount
|
||||
/// @param _makerCollaToWithdraw withdraw maker
|
||||
/// @param _compoundDepositAmount deposit compound
|
||||
/// @param _compoundDebtAmount borrow compound
|
||||
/// @param _fees pay the Gelato Provider (TO DO: unsafe)
|
||||
function _setInstaMemoryUints(
|
||||
uint256 _makerDebtRepaymentAmount,
|
||||
uint256 _makerCollaToWithdraw,
|
||||
uint256 _compoundDepositAmount,
|
||||
uint256 _compoundDebtAmount,
|
||||
uint256 _fees
|
||||
) internal {
|
||||
setUint(600, _makerDebtRepaymentAmount); // borrow flashloan
|
||||
setUint(601, _makerDebtRepaymentAmount); // payback maker
|
||||
setUint(602, _makerCollaToWithdraw); // withdraw maker
|
||||
setUint(603, _compoundDepositAmount); // deposit compound
|
||||
setUint(604, _compoundDebtAmount); // borrow compound
|
||||
setUint(605, _fees); // pay the provider
|
||||
}
|
||||
|
||||
/// @notice Computes values needed for DebtBridge Maker->ProtocolB
|
||||
|
|
|
@ -6,7 +6,9 @@ const GelatoCoreLib = require("@gelatonetwork/core");
|
|||
const Helper = require("./helpers/Full-Refinance-External-Provider.helper");
|
||||
const helper = new Helper();
|
||||
|
||||
describe("Debt Bridge with External Provider", function () {
|
||||
// This test showcases how to submit a task refinancing a Users debt position from
|
||||
// Maker to Compound using Gelato
|
||||
describe("Full Debt Bridge refinancing loan from Maker to Compound", function () {
|
||||
this.timeout(0);
|
||||
if (hre.network.name !== "hardhat") {
|
||||
console.error("Test Suite is meant to be run on hardhat only");
|
||||
|
@ -64,7 +66,7 @@ describe("Debt Bridge with External Provider", function () {
|
|||
//#endregion
|
||||
});
|
||||
|
||||
it("#2 : User submit Debt refinancing task if market move", async function () {
|
||||
it("#2: User submits Debt refinancing task if market move to Gelato via DSA", async function () {
|
||||
//#region User submit a Debt Refinancing task if market move against him
|
||||
|
||||
// User submit the refinancing task if market move against him.
|
||||
|
@ -95,8 +97,8 @@ describe("Debt Bridge with External Provider", function () {
|
|||
});
|
||||
|
||||
const gelatoExternalProvider = new GelatoCoreLib.GelatoProvider({
|
||||
addr: address.providerAddress,
|
||||
module: contracts.dsaProviderModule.address,
|
||||
addr: address.providerAddress, // Gelato Provider Address
|
||||
module: contracts.dsaProviderModule.address, // Gelato DSA module
|
||||
});
|
||||
|
||||
const expiryDate = 0;
|
||||
|
@ -133,6 +135,10 @@ describe("Debt Bridge with External Provider", function () {
|
|||
//#endregion
|
||||
});
|
||||
|
||||
// This test showcases the part which is automatically done by the Gelato Executor Network on mainnet
|
||||
// Bots constatly check whether the submitted task is executable (by calling canExec)
|
||||
// If the task becomes executable (returns "OK"), the "exec" function will be called
|
||||
// which will execute the debt refinancing on behalf of the user
|
||||
it("#2: Use Maker Compound refinancing if the maker vault become unsafe after a market move.", async function () {
|
||||
// Steps
|
||||
// Step 1: Market Move against the user (Mock)
|
Loading…
Reference in New Issue
Block a user