ICollateralManager
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.16;
import { DataTypes } from "../protocol/libraries/types/DataTypes.sol";
interface ICollateralManager {
struct UpdateVars {
address borrowAsset;
uint256 accruedBorrowAmount;
uint256 updatedBorrowAmount;
}
/**
* @dev Emitted when a borrow is created
* @param initiator The address initiating the action
*/
event BorrowCreated(
address indexed initiator,
address indexed onBehalfOf,
uint256 indexed borrowId,
address collateral,
uint256 tokenId,
uint256 tokenValue,
address asset,
uint256 amount,
uint256 duration,
uint256 borrowIndex,
uint256 tokenizedId
);
/**
* @dev Emitted when a borrow is updated
* @param initiator The address initiating the action
*/
event BorrowUpdated(
address indexed initiator,
uint256 indexed borrowId,
address collateral,
uint256 tokenId,
address asset,
uint256 amountAdded,
uint256 amountTaken,
uint256 borrowIndex
);
/**
* @dev Emitted when a borrow is repaid by the borrower
* @param initiator The address initiating the action
*/
event BorrowRepaid(
address indexed initiator,
uint256 indexed borrowId,
address collateral,
uint256 tokenId,
address asset,
uint256 amount,
uint256 borrowIndex
);
/**
* @dev Emitted when a borrow is refinanced by the borrower
* @param initiator The address initiating the action
*/
event BorrowRefinanced(
address indexed initiator,
uint256 indexed borrowId,
address collateral,
uint256 tokenId,
address asset,
uint256 borrowAmount,
uint256 amountAdded,
uint256 amountTaken,
uint256 duration,
uint256 timestamp
);
/**
* @dev Emitted when a borrow is liquidate by the liquidator
* @param initiator The address initiating the action
*/
event BorrowLiquidated(
address indexed initiator,
uint256 indexed borrowId,
address collateral,
uint256 tokenId,
address asset,
uint256 amount,
uint256 borrowIndex
);
function borrowerOf(
uint256 borrowId
)
external
view
returns(address);
function getNumNftBorrows(address collateral) external view returns (uint256);
function getNumUserNftBorrows(address user, address collateral) external view returns (uint256);
function getBorrow(uint256 borrowId) external view returns (DataTypes.Borrow memory);
function getBorrowId(address collateral, uint256 tokenId) external view returns (uint256);
function setBorrowStatus(
uint256 borrowId,
DataTypes.BorrowStatus status
)
external
returns (bool);
function createBorrow(
address initiator,
address onBehalfOf,
address collateral,
uint256 tokenId,
uint256 tokenValue,
address asset,
uint256 amount,
uint256 duration,
uint256 borrowIndex,
uint256 reserveId
)
external
returns (
uint256 borrowId,
uint256 tokenizedId
);
function updateBorrow(
address initiator,
uint256 borrowId,
uint256 amountAdded,
uint256 amountTaken,
uint256 borrowIndex
)
external;
function repayBorrow(
address initiator,
uint256 borrowId,
uint256 amount,
uint256 borrowIndex
)
external;
function refinanceBorrow(
address initiator,
uint256 borrowId,
uint256 borrowAmount,
uint256 amountAdded,
uint256 amountTaken,
uint256 duration
)
external;
function getBorrowAmount(
uint256 borrowId
)
external
view
returns (address, uint256, address, uint256);
function getBorrowNumTokens(
uint256 borrowId
)
external
view
returns (uint256);
function getAuctionPrice(
uint256 borrowId
)
external
view
returns (uint256);
function getScaledAmount(
uint256 borrowId
)
external
view
returns(address, uint256);
function setBorrowAuctionCall(
uint256 borrowId,
uint256 auctionStartPrice,
uint256 auctionEndPrice,
uint256 auctionTimestamp,
address auctionCaller
)
external;
function liquidateBorrow(
uint256 borrowId
)
external;
function setBlacklisted(address collateral, uint256 tokenId, bool isBlacklisted_) external;
function isBlacklisted(address collateral, uint256 tokenId) external view returns (bool);
}
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.16;
library DataTypes {
/// -----------------------------------------------------------------------
/// Exec
/// -----------------------------------------------------------------------
struct ExecItemParams {
address target;
bytes payload;
}
struct ExecBatchItemParams {
address[] targets;
bytes[] payloads;
bool[] allowErrors;
}
/// -----------------------------------------------------------------------
/// P2Pool
/// -----------------------------------------------------------------------
enum BorrowStatus {
None, // Default zero
Active, // Open
Repaid, // Closed, paid by borrower
Auction, // In Auction
Liquidated // Closed, paid by liquidator
}
enum PriceGroupStatus {
None, // Default zero
Active, // Able to set / get prices
Paused, // Not able to perform any operation
Protected // Only able to get prices
}
struct Reserve {
ReserveConfigurationMap configuration;
address collateral;
address asset;
address fTokenAddress;
address stableDebtTokenAddress;
address variableDebtTokenAddress;
address interestRateAddress;
string assetPriceFeed;
uint256 id;
uint256 maxTokenSupply;
uint256 maxTokenId;
uint256 minTokenId;
uint128 liquidityIndex;
uint128 variableBorrowIndex;
uint128 currentLiquidityRate;
uint128 currentVariableBorrowRate;
uint40 lastUpdateTimestamp;
}
struct ReserveData {
address collateral;
address asset;
uint256 maxTokenId;
uint256 minTokenId;
}
struct InitReserveData {
uint256 reserveId;
address collateral;
address asset;
uint256 maxTokenId;
uint256 minTokenId;
address fTokenAddress;
address stableDebtTokenAddress;
address variableDebtTokenAddress;
address interestRateAddress;
string assetPriceFeed;
}
struct ReserveConfigurationMap {
//bit 0-15: LTV
//bit 16-31: Liq. threshold
//bit 32-47: Liq. bonus
//bit 48-55: Decimals
//bit 56: Reserve is active
//bit 57: reserve is frozen
//bit 58: borrowing is enabled
//bit 59: variable rate borrowing enabled
//bit 60-63: reserved
//bit 64-79: reserve factor
//bit 80-95: grace period
//bit 96-111: auction duration
//bit 112-127: auction start price multiple
uint256 data;
}
struct NFTPriceGroup {
NFTPriceGroupConfigurationMap configuration;
PriceGroupStatus status;
address[15] nfts;
uint256[15] reserveIds;
uint256[15] traitIds;
uint256[15] basePrices;
uint256 id;
}
struct NFTPriceGroupConfigurationMap {
//bit 0-15: DELTA_01
//bit 16-31: DELTA_02
//bit 32-47: DELTA_03
//bit 48-63: DELTA_04
//bit 64-79: DELTA_05
//bit 80-95: DELTA_06
//bit 96-111: DELTA_07
//bit 112-127: DELTA_08
//bit 128-143: DELTA_09
//bit 144-159: DELTA_10
//bit 160-175: DELTA_11
//bit 176-191: DELTA_12
//bit 192-207: DELTA_13
//bit 208-223: DELTA_14
//bit 224-239: DELTA_15
//bit 240: SIGN_01
//bit 241: SIGN_02
//bit 242: SIGN_03
//bit 243: SIGN_04
//bit 244: SIGN_05
//bit 245: SIGN_06
//bit 246: SIGN_07
//bit 247: SIGN_08
//bit 248: SIGN_09
//bit 249: SIGN_10
//bit 250: SIGN_11
//bit 251: SIGN_12
//bit 252: SIGN_13
//bit 253: SIGN_14
//bit 254: SIGN_15
uint256 data;
}
struct Auction {
address caller;
uint256 startPrice;
uint256 endPrice;
uint256 timestamp;
}
struct Borrow {
BorrowStatus status;
Collateral collateral;
Auction auction;
address borrower;
address erc20Token;
uint256 borrowAmount;
uint256 scaledAmount;
uint256 timestamp;
uint256 duration;
uint256 reserveId;
uint256 tokenizedId;
}
struct ExecuteDepositParams {
address initiator;
uint256 amount;
uint256 reserveId;
address onBehalfOf;
uint16 referralCode;
}
struct ExecuteBatchDepositParams {
address initiator;
uint256[] amounts;
uint256[] reserveIds;
address[] onBehalfOfs;
uint16[] referralCodes;
}
struct ExecuteWithdrawParams {
address initiator;
uint256 amount;
uint256 reserveId;
address to;
}
struct ExecuteBatchWithdrawParams {
address initiator;
uint256[] amounts;
uint256[] reserveIds;
address[] tos;
}
struct ExecuteBorrowParams {
address initiator;
uint256 amount;
uint256 tokenId;
uint256 tokenValue;
uint256 reserveId;
uint256 duration;
address onBehalfOf;
uint16 referralCode;
}
struct ExecuteBatchBorrowParams {
address initiator;
uint256[] amounts;
uint256[] tokenIds;
uint256[] tokenValues;
uint256[] reserveIds;
uint256 duration;
address onBehalfOf;
uint16 referralCode;
}
struct ExecuteRepayParams {
address initiator;
uint256 borrowId;
uint256 amount;
}
struct ExecuteBatchRepayParams {
address initiator;
uint256[] borrowIds;
uint256[] amounts;
}
struct ExecuteRefinanceParams {
address initiator;
uint256 borrowId;
uint256 amount;
uint256 duration;
}
struct ExecuteBatchRefinanceParams {
address initiator;
uint256[] borrowIds;
uint256[] amounts;
uint256[] durations;
}
struct ExecuteAuctionParams {
address initiator;
uint256 borrowId;
address onBehalfOf;
}
struct ExecuteBatchAuctionParams {
address initiator;
uint256[] borrowIds;
address[] onBehalfOfs;
}
struct ExecuteBidParams {
address initiator;
address asset;
uint256 amount;
uint256 borrowId;
address onBehalfOf;
}
struct ExecuteBatchBidParams {
address initiator;
address[] assets;
uint256[] amounts;
uint256[] borrowIds;
address[] onBehalfOfs;
}
/// -----------------------------------------------------------------------
/// Tokenized
/// -----------------------------------------------------------------------
struct TokenizedLoan {
address collateral;
uint256 tokenId;
uint256 id;
}
/// -----------------------------------------------------------------------
/// P2Peer
/// -----------------------------------------------------------------------
enum LoanStatus {
None, // Default zero
Escrow, // Open
Repaid, // Closed, lender received repayment
Refinanced, // Closed, lender received repayment
Foreclosed // Closed, lender received collateral
}
enum Side { Offer, Listing }
enum SignatureVersion { Single, Bulk }
enum CollateralType { ERC721, ERC1155 } //TODO
enum LoanType {
Loan,
Trait,
Collection,
Bundle,
Renegotiation,
Refinancing
}
struct Terms {
LoanType loanType;
/* Order collaterlTypes - empty item if not isBundle. */
CollateralType[] collateralTypes;
CollateralType collateralType;
/* Order collaterals & tokenIds - empty if not isBundle. */
address[] collaterals;
uint256[] tokenIds;
/* Order values - empty item if not ERC1155. */
uint256[] values;
/* Order collateral & tokenId - address(0) if isBundle. */
address collateral;
uint256 tokenId;
/* Order value - empty item if not ERC1155. */
uint256 value;
address asset;
uint256 amount;
/* Order maximumRepayment - used for both fixed price and pro-rata loans. */
uint256 maximumRepayment;
/* Order minimumRepayment - used for pro-rata loans, 0 if none */
uint256 minimumRepayment;
/* Order interestRateInBasisPoints - used for pro-rata loans. */
uint256 interestRateInBasisPoints;
uint256 duration;
/* Loan isProRata - used enable pro-rata loan repayments. */
bool isProRata;
bool isBundle;
/* Order loanId - 0 if creating a new loan. */
uint256 loanId;
/* Order fee - paid on renegotiation. */
uint256 fee;
}
struct Order {
address user;
/* Referrer - for new loans & refinancing (borrower-side). */
address referrer;
Side side;
Terms terms;
/* Order counterparty - address(0) for open order. */
address counterparty;
bool isInstantExecution;
/* Order loanRepayment - for refinancing. */
uint256 loanRepayment;
uint256 listingTime;
uint256 expirationTime;
uint256 salt;
/* Order message - for renegotiations. */
string message;
bytes extraParams;
/* Borrow Id - for p2pool orders. */
uint256 borrowId;
/* Reserve Id - for fToken orders. */
uint256 reserveId;
}
struct Input {
Order order;
uint8 v;
bytes32 r;
bytes32 s;
bytes extraSignature;
SignatureVersion signatureVersion;
uint256 blockNumber;
}
struct Execution {
Input offer;
Input listing;
}
struct Collateral {
/* Loan collateralType - ERC721 or ERC1155. */
CollateralType collateralType;
address collateral;
uint256 tokenId;
/* Loan value - collateral token amount (ERC1155, only). */
uint256 value;
}
struct Collaterals {
/* Loan collateralType - ERC721 or ERC1155. */
CollateralType[] collateralTypes;
address[] collaterals;
uint256[] tokenIds;
/* Loan value - collateral token amount (ERC1155, only). */
uint256[] values;
}
struct Principal {
address asset;
uint256 amount;
}
struct Interest {
/* Loan:Interest rate - in basis points (1/100th of a percent), used in pro-rata loans. */
uint256 rate;
/* Loan.Interest isProRata - to enable pro-rata loan repayments. */
bool isProRata;
}
struct Repayment {
/* Loan Repayment.maximum - used in both fixed price & pro-rata loans. */
uint256 maximum;
/* Loan Repayment.minimum - (optional) used in pro-rata loans. */
uint256 minimum;
}
struct Loan {
LoanStatus status;
Collateral collateral;
Principal principal;
Interest interest;
Repayment repayment;
address borrower;
address lender;
address referrer;
uint256 timestamp;
uint256 duration;
/* Loan tokenizedId - tokenId of promissoryNote and obligationReceipt. */
uint256 tokenizedId;
}
struct LoanBundle {
LoanStatus status;
Collaterals collaterals;
Principal principal;
Interest interest;
Repayment repayment;
address borrower;
address lender;
address referrer;
uint256 timestamp;
uint256 duration;
/* Loan tokenizedId - tokenId of promissoryNote and obligationReceipt. */
uint256 tokenizedId;
}
struct ExecuteNewLoanParams {
DataTypes.Terms terms;
address borrower;
address lender;
address referrer;
/* Borrow Id - for p2pool Orders */
uint256 borrowId;
/* Reserve Id - for fToken Orders */
uint256 reserveId;
}
struct ExecuteRepayLoanParams {
uint256 loanId;
uint256 lendingFactor;
/* Reserve Id - for fToken repayment */
uint256 reserveId;
}
struct ExecuteForecloseLoanParams {
uint256 loanId;
}
struct ExecuteRenegotiateLoanParams {
DataTypes.Terms terms;
address borrower;
address lender;
/* Reserve Ids - for fToken Orders */
uint256 borrowerReserveId;
uint256 lenderReserveId;
}
struct ExecuteRefinanceLoanParams {
DataTypes.Terms terms;
address borrower;
address lender;
address referrer;
uint256 loanRepayment;
uint256 lendingFactor;
/* Reserve Ids - for fToken Orders */
uint256 borrowerReserveId;
uint256 lenderReserveId;
}
}
Last updated