Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-Currency Rollover #133

Merged
merged 27 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f01464c
feat(cross-currency-rollover): cross currency rollover contract and s…
Mouzayan May 29, 2024
af38b42
feat(cross-currency-rollover): update package json
Mouzayan May 29, 2024
f27f621
feat(cross-currency-rollover): updated yearn lock files
Mouzayan May 29, 2024
716a0a2
feat(cross-currency-rollover): update workflows test yml
Mouzayan May 29, 2024
ac12198
feat(cross-currency-rollover): print balances in script
Mouzayan May 30, 2024
030c43b
feat(cross-currency-rollover): kvk pr comments
Mouzayan May 30, 2024
22dd570
feat(cross-currency-rollover): remove flashloan. add script for princ…
Mouzayan Jun 2, 2024
1804c1a
feat(cross-currency-rollover): rename and separate function concerns
Mouzayan Jun 4, 2024
9636c04
feat(cross-currency-rollover): enable yul optimizer
Mouzayan Jun 4, 2024
591ff15
feat(cross-currency-rollover): make scripts options: with new lender …
Mouzayan Jun 4, 2024
f1e0083
feat(cross-currency-rollover): remove commented out code
Mouzayan Jun 4, 2024
279802e
feat(cross-currency-rollover): break up function to remove viair:true
Mouzayan Jun 4, 2024
3b90020
feat(cross-currency-rollover): revert change to test.yml
Mouzayan Jun 4, 2024
121605c
feat(cross-currency-rollover): keep swapparams outside of repaydata
Mouzayan Jun 5, 2024
d10f3d8
feat(cross-currency-rollover): eliminate fetchcurrentprice
Mouzayan Jun 6, 2024
5d9291a
feat(cross-currency-rollover): comment fixes
Mouzayan Jun 6, 2024
3dabfe9
feat(cross-currency-rollover): cleanup amounts.amounttoborrower and a…
Mouzayan Jun 6, 2024
a71368f
feat(cross-currency-rollover): update comment
Mouzayan Jun 6, 2024
848bda5
feat(cross-currency-rollover): add origination controller base and se…
Mouzayan Jun 7, 2024
653ed23
feat(cross-currency-rollover): add ocbase and separate out functional…
Mouzayan Jun 7, 2024
7c71949
feat(cross-currency-rollover): ocbase
Mouzayan Jun 10, 2024
0e2d23c
feat(cross-currency-rollover): ocbase
Mouzayan Jun 10, 2024
e6e9cde
feat(cross-currency-rollover): move helper functions from ocbase to oc
Mouzayan Jun 10, 2024
2c898b9
feat(cross-currency-rollover): kvk comment fixes
Mouzayan Jun 10, 2024
05b422c
feat(cross-currency-rollover): comment fixes
Mouzayan Jun 11, 2024
b1f28a5
feat(cross-currency-rollover): comment fixes
Mouzayan Jun 12, 2024
776dcc9
feat(cross-currency-rollover): kvk comment fixes
Mouzayan Jun 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 28 additions & 0 deletions contracts/interfaces/ICrossCurrencyRollover.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

import "../libraries/LoanLibrary.sol";
import "../libraries/OriginationLibrary.sol";

import "./IOriginationController.sol";

interface ICrossCurrencyRollover {
// =========================== EVENTS ==========================
event PausedStateChanged(bool isPaused);
event CurrencyRollover(address indexed lender, address indexed borrower, uint256 collateralTokenId, uint256 newLoanId);

// ================== CROSS CURRENCY ROLLOVER ==================
function rolloverCrossCurrencyLoan(
uint256 oldLoanId,
LoanLibrary.LoanTerms calldata loanTerms,
address lender,
IOriginationController.Signature calldata sig,
IOriginationController.SigProperties calldata sigProperties,
LoanLibrary.Predicate[] calldata itemPredicates,
OriginationLibrary.SwapParameters calldata swapParams
) external;

// ======================== OWNER OPS =========================
function pause(bool _pause) external;
}
52 changes: 3 additions & 49 deletions contracts/interfaces/IOriginationController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,18 @@

pragma solidity 0.8.18;

import "./IOriginationControllerBase.sol";

import "../libraries/LoanLibrary.sol";

interface IOriginationController {
interface IOriginationController is IOriginationControllerBase {
// ============= Data Types =============

struct BorrowerData {
address borrower;
bytes callbackData;
}

struct SigProperties {
uint160 nonce;
uint96 maxUses;
}

enum Side {
BORROW,
LEND
}

struct Signature {
uint8 v;
bytes32 r;
bytes32 s;
bytes extraData;
}

// ================ Events ================

event Approval(address indexed owner, address indexed signer, bool isApproved);

// ============= Loan Origination =============

function initializeLoan(
Expand All @@ -52,31 +33,4 @@ interface IOriginationController {
SigProperties calldata sigProperties,
LoanLibrary.Predicate[] calldata itemPredicates
) external returns (uint256 newLoanId);

// ================ Permission Management ================

function approve(address signer, bool approved) external;

function isApproved(address owner, address signer) external returns (bool);

function isSelfOrApproved(address target, address signer) external returns (bool);

// ============== Signature Verification ==============

function recoverTokenSignature(
LoanLibrary.LoanTerms calldata loanTerms,
Signature calldata sig,
SigProperties calldata sigProperties,
Side side,
address signingCounterparty
) external view returns (bytes32 sighash, address signer);

function recoverItemsSignature(
LoanLibrary.LoanTerms calldata loanTerms,
Signature calldata sig,
LoanLibrary.Predicate[] calldata itemPredicates,
SigProperties calldata sigProperties,
Side side,
address signingCounterparty
) external view returns (bytes32 sighash, address signer);
}
57 changes: 57 additions & 0 deletions contracts/interfaces/IOriginationControllerBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

import "../libraries/LoanLibrary.sol";

interface IOriginationControllerBase {
// ============= Data Types =============

struct SigProperties {
uint160 nonce;
uint96 maxUses;
}

enum Side {
BORROW,
LEND
}

struct Signature {
uint8 v;
bytes32 r;
bytes32 s;
bytes extraData;
}

// ================ Events ================

event Approval(address indexed owner, address indexed signer, bool isApproved);

// ================ Permission Management ================

function approve(address signer, bool approved) external;

function isApproved(address owner, address signer) external returns (bool);

function isSelfOrApproved(address target, address signer) external returns (bool);

// ============== Signature Verification ==============

function recoverTokenSignature(
LoanLibrary.LoanTerms calldata loanTerms,
Signature calldata sig,
SigProperties calldata sigProperties,
Side side,
address signingCounterparty
) external view returns (bytes32 sighash, address signer);

function recoverItemsSignature(
LoanLibrary.LoanTerms calldata loanTerms,
Signature calldata sig,
LoanLibrary.Predicate[] calldata itemPredicates,
SigProperties calldata sigProperties,
Side side,
address signingCounterparty
) external view returns (bytes32 sighash, address signer);
}
5 changes: 5 additions & 0 deletions contracts/libraries/OriginationLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ library OriginationLibrary {
RolloverAmounts migrationAmounts;
}

struct SwapParameters {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be part of ICrossCurrencyRollover, since it is only used in the cross-currency case

uint256 minAmountOut;
uint24 poolFeeTier;
}

// ======================================= CONSTANTS ==============================================

/// @notice EIP712 type hash for bundle-based signatures.
Expand Down
Loading
Loading