Skip to content

Commit

Permalink
feat(cross-currency-rollover): comment fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mouzayan committed Jun 11, 2024
1 parent 2c898b9 commit 05b422c
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 96 deletions.
67 changes: 67 additions & 0 deletions contracts/errors/Lending.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
80 changes: 0 additions & 80 deletions contracts/errors/Rollover.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/rollover/CrossCurrencyRollover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
CCR_LenderIsBorrower,
CCR_CallerNotBorrower,
CCR_ZeroAddress
} from "../errors/Rollover.sol";
} from "../errors/Lending.sol";

contract CrossCurrencyRollover is
ICrossCurrencyRollover,
Expand Down
10 changes: 5 additions & 5 deletions scripts/rollover/cross-currency-rollover-fees-on.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ export async function main(): Promise<void> {
);

// 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
Expand Down Expand Up @@ -301,15 +301,15 @@ export async function main(): Promise<void> {
);

const swapParams: SwapParameters = {
minAmountOut: amountOwed.div(2),
minAmountOut: NEW_PRINCIPAL_OLD_CURRENCY,
poolFeeTier: poolFeeTier,
};

console.log();
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
Expand Down
12 changes: 6 additions & 6 deletions scripts/rollover/cross-currency-rollover-new-lender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function main(): Promise<void> {
originationController,
crossCurrencyRollover,
loanCore
} = resources;
} = resources;

const erc20Factory = await ethers.getContractFactory("ERC20");
const dai = <ERC20>erc20Factory.attach(DAIAddress);
Expand Down Expand Up @@ -247,11 +247,11 @@ export async function main(): Promise<void> {
);

// 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
Expand Down Expand Up @@ -282,15 +282,15 @@ export async function main(): Promise<void> {
);

const swapParams: SwapParameters = {
minAmountOut: amountOwed.div(2),
minAmountOut: NEW_PRINCIPAL_OLD_CURRENCY,
poolFeeTier: poolFeeTier,
};

console.log();
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
Expand Down
8 changes: 4 additions & 4 deletions scripts/rollover/cross-currency-rollover-same-lender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ export async function main(): Promise<void> {
);

// 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));

Expand Down Expand Up @@ -277,15 +277,15 @@ export async function main(): Promise<void> {
);

const swapParams: SwapParameters = {
minAmountOut: amountOwed.div(2),
minAmountOut: NEW_PRINCIPAL_OLD_CURRENCY,
poolFeeTier: poolFeeTier,
};

console.log();
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
Expand Down

0 comments on commit 05b422c

Please sign in to comment.