-
Notifications
You must be signed in to change notification settings - Fork 9
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
Changes from 7 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 af38b42
feat(cross-currency-rollover): update package json
Mouzayan f27f621
feat(cross-currency-rollover): updated yearn lock files
Mouzayan 716a0a2
feat(cross-currency-rollover): update workflows test yml
Mouzayan ac12198
feat(cross-currency-rollover): print balances in script
Mouzayan 030c43b
feat(cross-currency-rollover): kvk pr comments
Mouzayan 22dd570
feat(cross-currency-rollover): remove flashloan. add script for princ…
Mouzayan 1804c1a
feat(cross-currency-rollover): rename and separate function concerns
Mouzayan 9636c04
feat(cross-currency-rollover): enable yul optimizer
Mouzayan 591ff15
feat(cross-currency-rollover): make scripts options: with new lender …
Mouzayan f1e0083
feat(cross-currency-rollover): remove commented out code
Mouzayan 279802e
feat(cross-currency-rollover): break up function to remove viair:true
Mouzayan 3b90020
feat(cross-currency-rollover): revert change to test.yml
Mouzayan 121605c
feat(cross-currency-rollover): keep swapparams outside of repaydata
Mouzayan d10f3d8
feat(cross-currency-rollover): eliminate fetchcurrentprice
Mouzayan 5d9291a
feat(cross-currency-rollover): comment fixes
Mouzayan 3dabfe9
feat(cross-currency-rollover): cleanup amounts.amounttoborrower and a…
Mouzayan a71368f
feat(cross-currency-rollover): update comment
Mouzayan 848bda5
feat(cross-currency-rollover): add origination controller base and se…
Mouzayan 653ed23
feat(cross-currency-rollover): add ocbase and separate out functional…
Mouzayan 7c71949
feat(cross-currency-rollover): ocbase
Mouzayan 0e2d23c
feat(cross-currency-rollover): ocbase
Mouzayan e6e9cde
feat(cross-currency-rollover): move helper functions from ocbase to oc
Mouzayan 2c898b9
feat(cross-currency-rollover): kvk comment fixes
Mouzayan 05b422c
feat(cross-currency-rollover): comment fixes
Mouzayan b1f28a5
feat(cross-currency-rollover): comment fixes
Mouzayan 776dcc9
feat(cross-currency-rollover): kvk comment fixes
Mouzayan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// 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 The flash loan callback caller is not recognized. The caller must be the flash | ||
* loan provider. | ||
* | ||
* @param caller The address of the caller. | ||
* @param lendingPool Expected address of the flash loan provider. | ||
*/ | ||
error CCR_UnknownCaller(address caller, address lendingPool); | ||
|
||
/** | ||
* @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 Borrower address is not cached of the flash loan callback. | ||
*/ | ||
error CCR_BorrowerNotCached(); | ||
|
||
/** | ||
* @notice The borrower address saved in the rollover contract is not the same as the | ||
* borrower address provided in the flash loan operation data. The initiator of | ||
* the flash loan must be the rollover contract. | ||
* | ||
* @param providedBorrower Borrower address passed in the flash loan operation data. | ||
* @param cachedBorrower Borrower address saved in the rollover contract. | ||
*/ | ||
error CCR_UnknownBorrower(address providedBorrower, address cachedBorrower); | ||
|
||
/** | ||
* @notice The borrower state must be address(0) to initiate a rollover sequence. | ||
* | ||
* @param borrower The borrower address. | ||
*/ | ||
error CCR_BorrowerNotReset(address borrower); | ||
|
||
/** | ||
* @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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity 0.8.18; | ||
|
||
/// @title Provides functions for deriving a pool address from the factory, tokens, and the fee | ||
library PoolAddress { | ||
bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; | ||
|
||
/// @notice The identifying key of the pool | ||
struct PoolKey { | ||
address token0; | ||
address token1; | ||
uint24 fee; | ||
} | ||
|
||
/// @notice Returns PoolKey: the ordered tokens with the matched fee levels | ||
/// @param tokenA The first token of a pool, unsorted | ||
/// @param tokenB The second token of a pool, unsorted | ||
/// @param fee The fee level of the pool | ||
/// @return Poolkey The pool details with ordered token0 and token1 assignments | ||
function getPoolKey( | ||
address tokenA, | ||
address tokenB, | ||
uint24 fee | ||
) internal pure returns (PoolKey memory) { | ||
if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); | ||
return PoolKey({token0: tokenA, token1: tokenB, fee: fee}); | ||
} | ||
|
||
/// @notice Deterministically computes the pool address given the factory and PoolKey | ||
/// @param factory The Uniswap V3 factory contract address | ||
/// @param key The PoolKey | ||
/// @return pool The contract address of the V3 pool | ||
function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { | ||
require(key.token0 < key.token1); | ||
pool = address( | ||
uint160( | ||
uint256( | ||
keccak256( | ||
abi.encodePacked( | ||
hex'ff', | ||
factory, | ||
keccak256(abi.encode(key.token0, key.token1, key.fee)), | ||
POOL_INIT_CODE_HASH | ||
) | ||
) | ||
) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 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; | ||
|
||
function calculateProratedInterestAmount(uint256 loanId) external returns (uint256); | ||
|
||
function fetchCurrentPrice(address tokenIn, address tokenOut, uint24 poolFee) external returns (uint256 price); | ||
|
||
// ======================== OWNER OPS ========================= | ||
function pause(bool _pause) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,20 @@ library OriginationLibrary { | |
RolloverAmounts migrationAmounts; | ||
} | ||
|
||
struct SwapParameters { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be part of |
||
uint256 minAmountOut; | ||
uint24 poolFeeTier; | ||
} | ||
|
||
struct CrossCurrencyRepayData { | ||
uint256 oldLoanId; | ||
LoanLibrary.LoanTerms newLoanTerms; | ||
address borrower; | ||
address lender; | ||
RolloverAmounts rolloverAmounts; | ||
SwapParameters swapParameters; | ||
} | ||
|
||
// ======================================= CONSTANTS ============================================== | ||
|
||
/// @notice EIP712 type hash for bundle-based signatures. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Errors located in one place to make it possible to holistically look at all protocol failure cases" doesnt hold true since this is separate from all the other lending errors. What is the reasoning for making them separate? All of the other origination controller flavors are in the lending.sol file.