Add buffer to instaPool borrow, optimize gas cost by removing two extra instamemory write

This commit is contained in:
Shivva 2020-10-24 13:02:28 +02:00 committed by Luis Schliesske
parent a6107586d1
commit 0375fc4138
3 changed files with 14 additions and 12 deletions

View File

@ -306,9 +306,9 @@ contract ConnectGelatoDebtBridgeFromMaker is MakerResolver {
);
_setInstaMemoryUints(
wDaiDebtToMove,
wColToWithdrawFromMaker,
_add(wDaiDebtToMove, 1e18),
_sub(wColToWithdrawFromMaker, gasFeesPaidFromCol), // _wColToDepositInB
wDaiDebtToMove,
gasFeesPaidFromCol
);
}
@ -330,10 +330,12 @@ contract ConnectGelatoDebtBridgeFromMaker is MakerResolver {
_setInstaMemoryUints(
wDaiDebtToMove,
wColToWithdrawFromMaker,
_sub(wColToWithdrawFromMaker, gasFeesPaidFromCol), // _wColToDepositInB
wDaiDebtToMove,
gasFeesPaidFromCol
);
setUint(601, wDaiDebtToMove); // payback maker
setUint(602, wColToWithdrawFromMaker); // withdraw maker
}
/// @notice Computes values needed for DebtBridge Maker->ProtocolB
@ -477,14 +479,12 @@ contract ConnectGelatoDebtBridgeFromMaker is MakerResolver {
// _gasFeesPaidFromCol == _wColToWithdrawFromMaker - _wColToDepositInB
function _setInstaMemoryUints(
uint256 _wDaiDebtToMove,
uint256 _wColToWithdrawFromMaker,
uint256 _wDaiToBorrToInstaPool,
uint256 _wColToDepositInB,
uint256 _wDaiDebtToMove,
uint256 _gasFeesPaidFromCol
) internal virtual {
setUint(600, _wDaiDebtToMove); // borrow flashloan
setUint(601, _wDaiDebtToMove); // payback maker
setUint(602, _wColToWithdrawFromMaker); // withdraw maker
setUint(600, _wDaiToBorrToInstaPool); // borrow flashloan
setUint(603, _wColToDepositInB); // deposit compound
setUint(604, _wDaiDebtToMove); // borrow compound
setUint(605, _gasFeesPaidFromCol); // pay the provider

View File

@ -263,8 +263,10 @@ describe("Full Debt Bridge refinancing loan from Maker to Compound", function ()
// DSA contain 1000 DAI
expect(
await contracts.daiToken.balanceOf(contracts.dsa.address)
).to.be.equal(constants.MAKER_INITIAL_DEBT);
(await contracts.daiToken.balanceOf(contracts.dsa.address)).sub(
constants.MAKER_INITIAL_DEBT
)
).to.be.lt(ethers.utils.parseUnits("2", 0));
//#endregion
});

View File

@ -503,7 +503,7 @@ class Helper {
data: await hre.run("abi-encode-withselector", {
abi: ConnectMaker.abi,
functionname: "payback",
inputs: [vaultId, 0, "601", 0],
inputs: [vaultId, ethers.constants.MaxUint256, 0, 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
@ -515,7 +515,7 @@ class Helper {
data: await hre.run("abi-encode-withselector", {
abi: ConnectMaker.abi,
functionname: "withdraw",
inputs: [vaultId, 0, "602", 0],
inputs: [vaultId, ethers.constants.MaxUint256, 0, 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});