From 05b422cdae2644b154f340252680e4894b976cbb Mon Sep 17 00:00:00 2001 From: Mouzayan Delbourgo Date: Tue, 11 Jun 2024 15:47:59 -0400 Subject: [PATCH] feat(cross-currency-rollover): comment fixes --- contracts/errors/Lending.sol | 67 ++++++++++++++++ contracts/errors/Rollover.sol | 80 ------------------- contracts/rollover/CrossCurrencyRollover.sol | 2 +- .../cross-currency-rollover-fees-on.ts | 10 +-- .../cross-currency-rollover-new-lender.ts | 12 +-- .../cross-currency-rollover-same-lender.ts | 8 +- 6 files changed, 83 insertions(+), 96 deletions(-) delete mode 100644 contracts/errors/Rollover.sol diff --git a/contracts/errors/Lending.sol b/contracts/errors/Lending.sol index 83b9b1b5..35ab9df1 100644 --- a/contracts/errors/Lending.sol +++ b/contracts/errors/Lending.sol @@ -276,6 +276,73 @@ error OCM_CollateralMismatch( */ error OCM_LenderIsBorrower(); +// ================================== CROSS CURRENCY ROLLOVER ==================================== +/// @notice All errors prefixed with CCR_, to separate from other contracts in the protocol. + +/** + * @notice Only the holder of the borrowerNote can rollover their loan. + */ +error CCR_CallerNotBorrower(); + +/** + * @notice Contract is paused, rollover operations are blocked. + */ +error CCR_Paused(); + +/** + * @notice The rollover contract is already in the specified pause state. + */ +error CCR_StateAlreadySet(); + +/** + * @notice Ensure valid loan state for loan lifecycle operations. + * + * @param state Current state of a loan according to LoanState enum. + */ +error CCR_InvalidState(uint8 state); + +/** + * @notice Signer is attempting to take the wrong side of the loan. + * + * @param signer The address of the external signer. + */ +error CCR_SideMismatch(address signer); + +/** + * @notice New currency should not match original loan currency. + * + * @param oldCurrency The currency of the active loan. + * @param newCurrency The currency of the new loan. + */ +error CCR_SameCurrency(address oldCurrency, address newCurrency); + +/** + * @notice New collateral does not match for a loan migration request. + * + * @param oldCollateralAddress The address of the active loan's collateral. + * @param newCollateralAddress The token ID of the active loan's collateral. + * @param oldCollateralId The address of the new loan's collateral. + * @param newCollateralId The token ID of the new loan's collateral. + */ +error CCR_CollateralMismatch( + address oldCollateralAddress, + uint256 oldCollateralId, + address newCollateralAddress, + uint256 newCollateralId +); + +/** + * @notice The lender specified for a migration cannot be the current borrower. + */ +error CCR_LenderIsBorrower(); + +/** + * @notice Zero address passed in where not allowed. + * + * @param addressType The name of the parameter for which a zero address was provided. + */ +error CCR_ZeroAddress(string addressType); + // ================================= REFINANCE CONTROLLER ===================================== /// @notice All errors prefixed with REFI_, to separate from other contracts in the protocol. diff --git a/contracts/errors/Rollover.sol b/contracts/errors/Rollover.sol deleted file mode 100644 index f0452e36..00000000 --- a/contracts/errors/Rollover.sol +++ /dev/null @@ -1,80 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity 0.8.18; - -/** - * @title Rollover Errors - * @author Non-Fungible Technologies, Inc. - * - * This file contains custom errors for the cross currency rollover contract, with errors - * prefixed by "CCR_" for CrossCurrencyRollover. - * Errors located in one place to make it possible to holistically look at all - * protocol failure cases. - */ - -// ================================== CROSS CURRENCY ROLLOVER ==================================== -/// @notice All errors prefixed with CCR_, to separate from other contracts in the protocol. - -/** - * @notice Only the holder of the borrowerNote can rollover their loan. - */ -error CCR_CallerNotBorrower(); - -/** - * @notice Contract is paused, rollover operations are blocked. - */ -error CCR_Paused(); - -/** - * @notice The rollover contract is already in the specified pause state. - */ -error CCR_StateAlreadySet(); - -/** - * @notice Ensure valid loan state for loan lifecycle operations. - * - * @param state Current state of a loan according to LoanState enum. - */ -error CCR_InvalidState(uint8 state); - -/** - * @notice Signer is attempting to take the wrong side of the loan. - * - * @param signer The address of the external signer. - */ -error CCR_SideMismatch(address signer); - -/** - * @notice New currency should not match original loan currency. - * - * @param oldCurrency The currency of the active loan. - * @param newCurrency The currency of the new loan. - */ -error CCR_SameCurrency(address oldCurrency, address newCurrency); - -/** - * @notice New collateral does not match for a loan migration request. - * - * @param oldCollateralAddress The address of the active loan's collateral. - * @param newCollateralAddress The token ID of the active loan's collateral. - * @param oldCollateralId The address of the new loan's collateral. - * @param newCollateralId The token ID of the new loan's collateral. - */ -error CCR_CollateralMismatch( - address oldCollateralAddress, - uint256 oldCollateralId, - address newCollateralAddress, - uint256 newCollateralId -); - -/** - * @notice The lender specified for a migration cannot be the current borrower. - */ -error CCR_LenderIsBorrower(); - -/** - * @notice Zero address passed in where not allowed. - * - * @param addressType The name of the parameter for which a zero address was provided. - */ -error CCR_ZeroAddress(string addressType); diff --git a/contracts/rollover/CrossCurrencyRollover.sol b/contracts/rollover/CrossCurrencyRollover.sol index 6ca156d1..5571a4fa 100644 --- a/contracts/rollover/CrossCurrencyRollover.sol +++ b/contracts/rollover/CrossCurrencyRollover.sol @@ -29,7 +29,7 @@ import { CCR_LenderIsBorrower, CCR_CallerNotBorrower, CCR_ZeroAddress -} from "../errors/Rollover.sol"; +} from "../errors/Lending.sol"; contract CrossCurrencyRollover is ICrossCurrencyRollover, diff --git a/scripts/rollover/cross-currency-rollover-fees-on.ts b/scripts/rollover/cross-currency-rollover-fees-on.ts index d6c62a8a..83955a6b 100644 --- a/scripts/rollover/cross-currency-rollover-fees-on.ts +++ b/scripts/rollover/cross-currency-rollover-fees-on.ts @@ -266,11 +266,11 @@ export async function main(): Promise { ); // price of Dai in wETH at block number: 18852467 - const price = BigNumber.from("0x018974567f22d0"); + const price = ethers.utils.parseUnits(".000432607737094864", 18); console.log("Price of DAI in wETH at block number: 18852467: ", ethers.utils.formatUnits(price, 18)); // changing the value of NEW_PRINCIPAL will affect whether the borrower will - // need to provide additional funds to pay the difference - const NEW_PRINCIPAL_OLD_CURRENCY = amountOwed.div(2); + // need to provide additional funds to pay the difference. amountOwed is "3017.260316780821917808" + const NEW_PRINCIPAL_OLD_CURRENCY = ethers.utils.parseUnits("1500", 18); // calculate the new principal amount in wETH let NEW_PRINCIPAL = NEW_PRINCIPAL_OLD_CURRENCY.mul(price).div(ethers.utils.parseUnits("1", 18)); // account for 3% slippage @@ -301,7 +301,7 @@ export async function main(): Promise { ); const swapParams: SwapParameters = { - minAmountOut: amountOwed.div(2), + minAmountOut: NEW_PRINCIPAL_OLD_CURRENCY, poolFeeTier: poolFeeTier, }; @@ -309,7 +309,7 @@ export async function main(): Promise { console.log("Approvals for rollover loan..."); // new lender approves WETH amount to contract - const approveWETHTx = await weth.connect(newLender).approve(crossCurrencyRollover.address, wethAmount); + const approveWETHTx = await weth.connect(newLender).approve(crossCurrencyRollover.address, NEW_PRINCIPAL); await approveWETHTx.wait(); // if new principal amount is less than the amount owed diff --git a/scripts/rollover/cross-currency-rollover-new-lender.ts b/scripts/rollover/cross-currency-rollover-new-lender.ts index 04121fa6..8359d371 100644 --- a/scripts/rollover/cross-currency-rollover-new-lender.ts +++ b/scripts/rollover/cross-currency-rollover-new-lender.ts @@ -61,7 +61,7 @@ export async function main(): Promise { originationController, crossCurrencyRollover, loanCore - } = resources; + } = resources; const erc20Factory = await ethers.getContractFactory("ERC20"); const dai = erc20Factory.attach(DAIAddress); @@ -247,11 +247,11 @@ export async function main(): Promise { ); // price of Dai in wETH at block number: 18852467 - const price = BigNumber.from("0x018974567f22d0"); + const price = ethers.utils.parseUnits(".000432607737094864", 18); console.log("Price of DAI in wETH at block number: 18852467: ", ethers.utils.formatUnits(price, 18)); // changing the value of NEW_PRINCIPAL will affect whether the borrower will - // need to provide additional funds to pay the difference - const NEW_PRINCIPAL_OLD_CURRENCY = amountOwed.div(2); + // need to provide additional funds to pay the difference. amountOwed is "3017.260316780821917808" + const NEW_PRINCIPAL_OLD_CURRENCY = ethers.utils.parseUnits("1500", 18); // calculate the new principal amount in wETH let NEW_PRINCIPAL = NEW_PRINCIPAL_OLD_CURRENCY.mul(price).div(ethers.utils.parseUnits("1", 18)); // account for 3% slippage @@ -282,7 +282,7 @@ export async function main(): Promise { ); const swapParams: SwapParameters = { - minAmountOut: amountOwed.div(2), + minAmountOut: NEW_PRINCIPAL_OLD_CURRENCY, poolFeeTier: poolFeeTier, }; @@ -290,7 +290,7 @@ export async function main(): Promise { console.log("Approvals for rollover loan..."); // new lender approves WETH amount to contract - const approveWETHTx = await weth.connect(newLender).approve(crossCurrencyRollover.address, wethAmount); + const approveWETHTx = await weth.connect(newLender).approve(crossCurrencyRollover.address, NEW_PRINCIPAL); await approveWETHTx.wait(); // if new principal amount is less than the amount owed diff --git a/scripts/rollover/cross-currency-rollover-same-lender.ts b/scripts/rollover/cross-currency-rollover-same-lender.ts index 5b06dace..b8da4dc0 100644 --- a/scripts/rollover/cross-currency-rollover-same-lender.ts +++ b/scripts/rollover/cross-currency-rollover-same-lender.ts @@ -241,11 +241,11 @@ export async function main(): Promise { ); // price of Dai in wETH at block number: 18852467 - const price = BigNumber.from("0x018974567f22d0"); + const price = ethers.utils.parseUnits(".000432607737094864", 18); console.log("Price of DAI in wETH at block number: 18852467: ", ethers.utils.formatUnits(price, 18)); // changing the value of NEW_PRINCIPAL will affect whether the borrower will // need to provide additional funds to pay the difference - const NEW_PRINCIPAL_OLD_CURRENCY = amountOwed; + const NEW_PRINCIPAL_OLD_CURRENCY = ethers.utils.parseUnits("3017.260316780821917808", 18); // calculate the new principal amount in wETH let NEW_PRINCIPAL = amountOwed.mul(price).div(ethers.utils.parseUnits("1", 18)); @@ -277,7 +277,7 @@ export async function main(): Promise { ); const swapParams: SwapParameters = { - minAmountOut: amountOwed.div(2), + minAmountOut: NEW_PRINCIPAL_OLD_CURRENCY, poolFeeTier: poolFeeTier, }; @@ -285,7 +285,7 @@ export async function main(): Promise { console.log("Approvals for rollover loan..."); // lender approves WETH amount to contract - const approveWETHTx = await weth.connect(lender).approve(crossCurrencyRollover.address, wethAmount); + const approveWETHTx = await weth.connect(lender).approve(crossCurrencyRollover.address, NEW_PRINCIPAL); await approveWETHTx.wait(); // if new principal amount is less than the amount owed