###### tags: `HouseMortage` 3/30 update # HouseMortage Intorduction ## Why HouseMortage? Traditional housing loans require banks to play the role of middlemen, resulting in a lot of interest income earned by banks, and lenders can only receive a small amount of interest from bank fixed deposits. We will make this more transparent through the power of blockchain, and lenders will be able to see the details of the houses they invest in and earn the interest income they deserve. ## Brifely introduce There are three roles and three currencies in our protocol. And the lending pool contracts structure we refer to those in Compound. ## Three roles ### Investor Those who use their USDC to invest house loans. ### Originator Those who check the house value , verify borrowers' credit , help borrowers to get loans ,and liquidate default mortage. ### Borrower (house owner) Those who mortage their house to get house loans. ## Three currencies ### hoUSD: Like the cToken in compound protocol. It can be bought by investers to fund loans that verified by the originator. ### HouseNft: NFTs that hold the information about the home and the borrow credit of the house House owner can use the NFT to borrow money in the lending pool. ### HouseMortage Token: governance token # HouseMortage contracts ## HouseNft ### For originators #### Mint HouseNft Before minting an Egg, an Originator must: 1. Show that the house is worth enough to cover the borrow credit of the HouseNft 2. Check that the address requesting for minting the Egg for is the rightful owner of the house. 3. Sign a Deed of Trust agreement with the owner to create a lien. 4. Record the lien on the public record with the region the house is in. ``` function verifyMintHouseNft( bool borrowable, uint borrowCredit , address houseOwner , uint32 originatorId, string memory houseInfo ) external ``` `borrowable`: whether this HouseNft can borrow money from the pool `borrowCredit`: the HouseNft borrow credit `houseOwner`: the address of the underlying house owner `originatorId`: the originatorId `houseInfo`: the underlying house info (stored by ipfs) ### For contract admin #### Add originator ``` function addOriginator( bool isValid, uint32 originatorId, uint256 permission, address originatorAddress, string memory originatorInfo ) external ``` `isValid`: whether this originator is valid `originatorId`: set the originatorId (every originator has one originatorId) `permission`: the credit `originatorAddress`: the wallet address of the originator `originatorInfo`: the originator info (ex. info of company , stored by ipfs) ### View function #### Check the Borrower (HouseNft owner) Borrow Credit ``` function getUserCreditData (address account) public view returns(uint) ``` `account`: the owner of the HouseNft `return`: the borrow credit of the account (calculated by all HouseNft the account own) #### Check the HouseNft Owner ``` function HouseNftOwnerOf(uint tokenId) public view returns (address) ``` `tokenId`: the tokenId of the HouseNft ## hoUSD contract (CErc20) ### View function #### getAccountSnapshot ``` function getAccountSnapshot(address account , uint tokenId) external view returns (uint, uint, uint, uint) ``` Get a snapshot of the account's balances, and the cached exchange rate TokenId=0 refer to supplier acount , other refer to borrower account ### For Lender #### Mint The mint function transfers an asset into the protocol, which begins accumulating interest based on the current Supply Rate for the asset. The lender receives a quantity of cTokens equal to the underlying tokens supplied, divided by the current Exchange Rate. ``` function mint(uint mintAmount) external returns (uint) ``` `mintAmount`: the amount lender whant to invest in (unit: USDC , scaled by 1e18) #### Redeem The redeem function converts a specified quantity of hoUSD into the underlying asset (USDC) , and returns them to the user. The amount of underlying tokens received is equal to the quantity of hoUSD redeemed, multiplied by the current Exchange Rate. The amount redeemed must be less than the user's Account Liquidity and the market's available liquidity. ``` function redeem(uint redeemTokens) external returns (uint) ``` `redeemTokens`: the amount lender whant to redeem investment (unit: hoUSD , scaled by 1e18) ``` function redeemUnderlying(uint redeemAmount) external returns (uint) ``` `redeemTokens`: the amount lender whant to redeem investment (unit: USDC , scaled by 1e18) #### Transfer function not yet ... ### For Borrower (The HouseNft owner who want to borrow money) #### Borrow The borrow function transfers an asset from the protocol to the borrower, and creates a borrow balance which begins accumulating interest based on the Borrow Rate for the asset. The amount borrowed must be less than the user's HouseNft borrow credit and the market's available liquidity. ``` function borrow(uint tokenId , uint borrowAmount) external returns (uint) ``` `msg.sender`: Borrower `borrowAmount` : The amount of the underlying asset to be borrowed. (unit: USDC , scaled by 1e18) #### Repay Borrow The repay function transfers an asset into the protocol, reducing the user's borrow balance. ``` function repayBorrow(uint tokenId , uint repayAmount) external returns (uint) ``` `msg.sender`:The account which borrowed the asset, and shall repay the borrow. `repayAmount`:The amount of the underlying borrowed asset to be repaid. A value of -1 (i.e. 2256 - 1) can be used to repay the full amount. (unit: USDC , scaled by 1e18) ``` function repayBorrowBehalf(address borrower, uint tokenId , uint repayAmount) ``` `msg.sender`:The account which shall repay the borrow. `borrower`:The account which borrowed the asset to be repaid. `repayAmount`:The amount of the underlying borrowed asset to be repaid. A value of -1 (i.e. 2256 - 1) can be used to repay the full amount. (unit: USDC , scaled by 1e18) ### For originator #### Liquidation function not yet ... ## OriginatorIncomeCalculator # extensions ### Compound Interest Rate Model refer to : https://ian.pw/posts/2020-12-20-understanding-compound-protocols-interest-rates ### Stable interest and Variable interest in AAVE proocol refer to : https://medium.com/aave/aave-borrowing-rates-upgraded-f6c8b27973a7 ### Mechanism of liquidation not yet ... ### Penalty if originators cheating not yet ... # Reference ## Compound Protocol ### white paper https://compound.finance/docs/ctokens#exchange-rate ### github https://github.com/compound-finance/compound-protocol ## Beacon ### white paper https://files.baconcoin.finance/bacon-protocol-whitepaper.pdf ### contract bHome: proxy : 0xb8919522331C59f5C16bDfAA6A121a6E03A91F62 logic : 0x118bE5A7250581AC96298d9405734bcD6e731e0e https://ethervm.io/decompile/0x781ad73f140815763d9A4D4752DAf9203361D07D BaconCoin: proxy: 0xa54d2EBfD977ad836203c85F18db2F0a0cF88854 logic : 0xDa4014D4F6f4acAf2934C045CC2969d11Ec87214 PropToken: proxy: 0x0E5af5cc3DF53Fcab8a92F07d6189e4189Ed6CEB logic : 0x7378318e4343117188F40377F4E2F50409B6EC31 mint propToken ?? proxy: 0xa42f6FB68607048dDe54FCd53D2195cc8ca5F486