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( _setInstaMemoryUints(
wDaiDebtToMove, _add(wDaiDebtToMove, 1e18),
wColToWithdrawFromMaker,
_sub(wColToWithdrawFromMaker, gasFeesPaidFromCol), // _wColToDepositInB _sub(wColToWithdrawFromMaker, gasFeesPaidFromCol), // _wColToDepositInB
wDaiDebtToMove,
gasFeesPaidFromCol gasFeesPaidFromCol
); );
} }
@ -330,10 +330,12 @@ contract ConnectGelatoDebtBridgeFromMaker is MakerResolver {
_setInstaMemoryUints( _setInstaMemoryUints(
wDaiDebtToMove, wDaiDebtToMove,
wColToWithdrawFromMaker,
_sub(wColToWithdrawFromMaker, gasFeesPaidFromCol), // _wColToDepositInB _sub(wColToWithdrawFromMaker, gasFeesPaidFromCol), // _wColToDepositInB
wDaiDebtToMove,
gasFeesPaidFromCol gasFeesPaidFromCol
); );
setUint(601, wDaiDebtToMove); // payback maker
setUint(602, wColToWithdrawFromMaker); // withdraw maker
} }
/// @notice Computes values needed for DebtBridge Maker->ProtocolB /// @notice Computes values needed for DebtBridge Maker->ProtocolB
@ -477,14 +479,12 @@ contract ConnectGelatoDebtBridgeFromMaker is MakerResolver {
// _gasFeesPaidFromCol == _wColToWithdrawFromMaker - _wColToDepositInB // _gasFeesPaidFromCol == _wColToWithdrawFromMaker - _wColToDepositInB
function _setInstaMemoryUints( function _setInstaMemoryUints(
uint256 _wDaiDebtToMove, uint256 _wDaiToBorrToInstaPool,
uint256 _wColToWithdrawFromMaker,
uint256 _wColToDepositInB, uint256 _wColToDepositInB,
uint256 _wDaiDebtToMove,
uint256 _gasFeesPaidFromCol uint256 _gasFeesPaidFromCol
) internal virtual { ) internal virtual {
setUint(600, _wDaiDebtToMove); // borrow flashloan setUint(600, _wDaiToBorrToInstaPool); // borrow flashloan
setUint(601, _wDaiDebtToMove); // payback maker
setUint(602, _wColToWithdrawFromMaker); // withdraw maker
setUint(603, _wColToDepositInB); // deposit compound setUint(603, _wColToDepositInB); // deposit compound
setUint(604, _wDaiDebtToMove); // borrow compound setUint(604, _wDaiDebtToMove); // borrow compound
setUint(605, _gasFeesPaidFromCol); // pay the provider 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 // DSA contain 1000 DAI
expect( expect(
await contracts.daiToken.balanceOf(contracts.dsa.address) (await contracts.daiToken.balanceOf(contracts.dsa.address)).sub(
).to.be.equal(constants.MAKER_INITIAL_DEBT); constants.MAKER_INITIAL_DEBT
)
).to.be.lt(ethers.utils.parseUnits("2", 0));
//#endregion //#endregion
}); });

View File

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