Skip to content

Latest commit

 

History

History
1343 lines (889 loc) · 28.5 KB

index.md

File metadata and controls

1343 lines (889 loc) · 28.5 KB

Solidity API

Life

An ERC-20 contract for ManageLife. Token Symbol: LIFE ($LIFE) This contract manages token rewards issued to ManageLife homeowners and investors. This contract also handles native token functions (EIP20 Token Standard).

startOfStakingRewards

mapping(uint256 => uint64) startOfStakingRewards

Mapping to get the start of staking for each NFTs. Start of stake data is in UNIX timestamp form.

_manageLifeToken

contract ManageLife _manageLifeToken

Instance of the MLIFE NFT contract

_investorsNft

contract ManageLifeInvestorsNFT _investorsNft

Instance of the NFTi contract

constructor

constructor(uint256 initialSupply) public

Set initial token supply before deploying.

pause

function pause() external

Security feature to Pause smart contracts transactions

unpause

function unpause() external

Unpausing the Paused transactions feature.

setManageLifeToken

function setManageLifeToken(address manageLifeToken_) external

Set the MLIFE's NFT contract address.

Important to set this after deployment.

Parameters

Name Type Description
manageLifeToken_ address Address of the MLIFE NFT contract

setNftiToken

function setNftiToken(address investorsNft_) external

Set the NFTi contract address.

Important to set this after deployment.

Parameters

Name Type Description
investorsNft_ address Contract address of NFTi contract.

manageLifeToken

function manageLifeToken() external view returns (address)

Return the MLIFE's contract address.

If set, this will return the MLIFE contract address

Return Values

Name Type Description
[0] address address .

manageLifeInvestorsNft

function manageLifeInvestorsNft() external view returns (address)

Return the NFTi's contract address.

If set, this will return the NFTi contract address.

Return Values

Name Type Description
[0] address address .

initStakingRewards

function initStakingRewards(uint256 tokenId) external

Initialize the Staking for an NFT.

Reverts if the caller is not the MLIFE contract address, MLIFE contact address is not set and if the contract is on-paused status.

Parameters

Name Type Description
tokenId uint256 TokenId of the NFT to start stake.

updateStartOfStaking

function updateStartOfStaking(uint256 tokenId, uint64 newStartDate) external

Update the start of stake of an NFT.

Since staking reward is based on time, this function will reset the stake start of an NFT that just recently claimed a token reward. This will be also an on-demand operation where the admins needs to reset the start of stake of an NFT, based off UNIX time.

Parameters

Name Type Description
tokenId uint256 TokenID of an NFT.
newStartDate uint64 New start of stake of an NFT. This param should be based on UNIX timestamp and into uint64 type.

claimableStakingRewards

function claimableStakingRewards(uint256 tokenId) public view returns (uint256)

Returns the claimable $LIFE token of an NFT.

MLIFE contract is dependent on this function in calculating the estimated staking rewards of an MLIFE. Formula in calculating the reward: Rewards = Current timestamp - StartOfStake timestamp * Life token issuance rate.

Parameters

Name Type Description
tokenId uint256 MLIFE's tokenId.

Return Values

Name Type Description
[0] uint256 uint256

burnLifeTokens

function burnLifeTokens(uint256 amount, uint256 tokenId) external

Burns $LIFE token from a sender's account.

Parameters

Name Type Description
amount uint256 Amount to burn.
tokenId uint256 TokenID of the NFT. This will be used as a param for access modifier.

mint

function mint(uint256 _amount) external

Function to mint additional token supply.

Newly minted amount will be credited to the contract owner.

Parameters

Name Type Description
_amount uint256 Additional amount to be minted.

mintInvestorsRewards

function mintInvestorsRewards(address investorAddress, uint256 _amount) external

Mint $LIFE token rewards for NFTi Investors.

NFTi contract depends on this function to mint $LIFE token rewards to investors. Newly minted tokens here will be credited directly to the investor's wallet address and NOT on the admin wallet.

Parameters

Name Type Description
investorAddress address Wallet address of the investor.
_amount uint256 Amount to be minted on the investor's address. Amount is based on the calculated staking rewards from NFTi contract.

claimStakingRewards

function claimStakingRewards(uint256 tokenId) public

Claim $LIFE token staking rewards.

_MLIFE's rewards issuance is reliant on this function. Once the user claim the rewards, this function will mint the tokens directly on the homeowner's wallet. Notes:

  • ML's admin or deployer wallet cannot claim $LIFE rewards.
  • Setting the MLIFE contract address is prerequisite in running this function.
  • This function can only be called by MLIFE holders.
  • A percentage of the token reward will be burned. Percentage will be determined by the ML admin.
  • Burn call will be handled separately by the frontend app._

Parameters

Name Type Description
tokenId uint256 MLIFE's tokenId.

onlyMembers

modifier onlyMembers(uint256 tokenId)

Custom access modifier to make sure that the caller of transactions are member of ML.

This identifies if the caller is an investor or NFTi holder.

Parameters

Name Type Description
tokenId uint256 TokenId of the NFT that needs to be checked.

ManageLifeInvestorsNFT

NFTi (ERC-721) contract for ManageLife Investors. Owning this NFT represents a investment in ManageLife's properties in real life. NFT Symbol: NFTi

lifeToken

contract Life lifeToken

Life token instance

_lifeTokenIssuanceRate

mapping(uint256 => uint256) _lifeTokenIssuanceRate

Mapping of NFTi tokenId to their issuance rates

stakingRewards

mapping(uint256 => uint64) stakingRewards

Mapping of NFTi tokenId to their start of staking

unlockDate

mapping(uint256 => uint256) unlockDate

Mapping of NFTi tokenId to their unlock dates

baseUri

string baseUri

Public base URI of ML's NFTs

BaseURIUpdated

event BaseURIUpdated(string _newURIAddress)

StakingClaimed

event StakingClaimed(uint256 tokenId)

TokenBurned

event TokenBurned(address burnFrom, uint256 amount)

TokenIssuanceRateUpdates

event TokenIssuanceRateUpdates(uint256 tokenId, uint256 newLifeTokenIssuanceRate)

StakingInitiated

event StakingInitiated(uint256 tokenId)

BurnedNft

event BurnedNft(uint256 tokenId)

constructor

constructor() public

mint

function mint(uint256 quantity) external

Mint new NFTis.

Parameters

Name Type Description
quantity uint256 Number of NFTis to be minted.

_baseURI

function _baseURI() internal view virtual returns (string)

Base URI for computing {tokenURI}. If set, the resulting URI for each token will be the concatenation of the baseURI and the tokenId. Empty by default, it can be overridden in child contracts.

setBaseURI

function setBaseURI(string newBaseUri) external

Function to change the base URI of the NFTs.

Giving the ML Admins an options in the future to change the URI of NFTs.

Parameters

Name Type Description
newBaseUri string New URI string.

setLifeToken

function setLifeToken(address lifeToken_) external

Set the Life token contract address.

Important to set this after deployment in order to build integration with the ERC20 contract.

Parameters

Name Type Description
lifeToken_ address $LIFE token contract address.

lifeTokenIssuanceRate

function lifeTokenIssuanceRate(uint256 tokenId) external view returns (uint256)

Query the life token issuance rate of an NFTi.

Default token issuance rate of NFTi is set by admins once the NFTi is issued to investor. Issuance rates varies per NFTi and is maintained by ML admins.

Parameters

Name Type Description
tokenId uint256 NFTi's tokenId.

Return Values

Name Type Description
[0] uint256 uint256

updateLifeTokenIssuanceRate

function updateLifeTokenIssuanceRate(uint256 tokenId, uint256 newLifeTokenIssuanceRate) external

Update life token issuance rate of an NFTi.

Updated issuance rate will be provided manually by ML admins. If an NFTi has an accumulated rewards already, the reward will be transferred first to the holder before updating the issuance rate.

Parameters

Name Type Description
tokenId uint256 NFTi's tokenId.
newLifeTokenIssuanceRate uint256 New issuance rate as provided by ML admins.

initStakingRewards

function initStakingRewards(uint256 tokenId) internal

Initialize the staking reward for an NFTi.

This will be triggered by the transfer hook and requires that the MLIFE contract should be set.

Parameters

Name Type Description
tokenId uint256 TokenId of NFTi to be set.

issueNftToInvestor

function issueNftToInvestor(address to, uint256 tokenId, uint256 lifeTokenIssuanceRate_) external

Function to issue an NFT to investors for the first time. Should be used by ML admins only.

Admins will be able to set an initial issuance rate for the NFT and initiate their staking. If the NFT has already an accumulated rewards, admins will not be able to transfer it to other address. Once this has been issued to an investor, the NFTi will be locked up by default for 1 year. At this period, the NFTi will not be able to be transfer to any contract or wallet address. Lock up period can be updated by admin wallet.

Parameters

Name Type Description
to address Address to issue the NFT
tokenId uint256 TokenId to be issued.
lifeTokenIssuanceRate_ uint256 Token issuance rate. Will be based on ML's mortgrage payment book.

checkClaimableStakingRewards

function checkClaimableStakingRewards(uint256 tokenId) public view returns (uint256)

Function to check the claimable staking reward of an NFT

claimStakingRewards

function claimStakingRewards(uint256 tokenId) public

Claim $LIFE token staking rewards.

_The rewards will be directly minted on the caller address. Once success, the timestamp of stakingRewards for that tokenId will be reset.

Parameters

Name Type Description
tokenId uint256 TokenId of the NFT.

burnTokens

function burnTokens(uint256 amount, uint256 tokenId) external

Burn $LIFE token rewards from an NFTi holder.

Burn percentage if being managed from the frontend app.

Parameters

Name Type Description
amount uint256 Calculated amount to be burned.
tokenId uint256 TokenId of the NFT, will be used as param in access modifier.

transferNft

function transferNft(address to, uint256 tokenId) external

Transfer NFTi function

_This transfer operation checks for some requirements before it successfully proceed. Requirements:

  • Sender must be the NFTi owner
  • NFTi should have no or have finished the locked up period._

Parameters

Name Type Description
to address Receiver of NFTi
tokenId uint256 NFTi tokenId to be sent.

returnNftToML

function returnNftToML(uint256 tokenId) external

Return the NFTi to ML wallet.

Use case - The investment period has been completed for a specificc NFTi and the asset needs to be returned. The investor should also clear the lockup period of the NFT so that the admins can transfer it to anyone at anytime. In an event that the NFTi has a claimable reward during the execution of this operation, the reward will be transferred first to the investor.

Parameters

Name Type Description
tokenId uint256 NFTi's tokenId.

setLockDate

function setLockDate(uint256 tokenId, uint256 _newLockDate) external

burnNFt

function burnNFt(uint256 tokenId) external

forceClaimNft

function forceClaimNft(uint256 tokenId) external

onlyInvestor

modifier onlyInvestor(uint256 tokenId)

Modifier checks to see if the token holder is an NFTi investor

ManageLife

NFT (ERC-721) contract for ManageLife Homeowners. An NFT represents a property or home ownership in real life. Properties are all being managed by ManageLife. NFT Symbol: MLIFE

lifeToken

contract Life lifeToken

marketplace

contract Marketplace marketplace

PROPERTY_CUSTODIAN

address PROPERTY_CUSTODIAN

This is the wallet address where all property NFTs will be stored as soon as the property got vacated or returned to ML.

lifeTokenIssuanceRate

mapping(uint256 => uint256) lifeTokenIssuanceRate

Mapping to get the issuance rate of a tokenId (propery).

fullyPaid

mapping(uint256 => bool) fullyPaid

Mapping to check the payment status of a tokenId.

FullyPaid

event FullyPaid(uint256 tokenId)

StakingInitialized

event StakingInitialized(uint256 tokenId)

PropertyReturned

event PropertyReturned(address from, uint256 tokenId)

PropertyCustodianUpdated

event PropertyCustodianUpdated(address newPropertyCustodian)

TokenIssuanceRateUpdated

event TokenIssuanceRateUpdated(uint256 token, uint256 newLifeTokenIssuanceRate)

constructor

constructor() public

baseUri

string baseUri

Public base URI of ML's NFTs

_baseURI

function _baseURI() internal view virtual returns (string)

Base URI for computing {tokenURI}. If set, the resulting URI for each token will be the concatenation of the baseURI and the tokenId. Empty by default, can be overridden in child contracts.

setBaseURI

function setBaseURI(string newBaseUri) external

Function to change the base URI of the NFTs.

Giving the ML Admins an options in the future to change the URI of NFTs.

Parameters

Name Type Description
newBaseUri string New URI string.

setMarketplace

function setMarketplace(address payable marketplace_) external

Function to set the Marketplace contract address.

Very important to set this after contract deployment.

Parameters

Name Type Description
marketplace_ address payable Address of the marketplace contract.

setLifeToken

function setLifeToken(address lifeToken_) external

Function to set the @LIFE token contract address.

Very important to set this after contract deployment.

Parameters

Name Type Description
lifeToken_ address Address of the $LIFE token contract.

markFullyPaid

function markFullyPaid(uint256 tokenId) external

Mark an NFT or property fully paid from all mortgages at ML.

This can only be executed by the contract deployer or admin wallet.

Parameters

Name Type Description
tokenId uint256 TokenId of the NFT.

mint

function mint(uint256 propertyId, uint256 lifeTokenIssuanceRate_) external

Function to mint new NFT properties.

Property ID will be the property number provided by the ML-NFT-API service. Life token issuance rate will be populated by the web3 admin from the portal app.

Parameters

Name Type Description
propertyId uint256 Property ID of the NFT. This will be provided by the FrontEnd app.
lifeTokenIssuanceRate_ uint256 Issuance rate percentage that is based on morgage payments maintained by ML.

burn

function burn(uint256 tokenId) public

Burn an NFT. Typical use case is remove an property from ML's custody.

Can only be executed by the admin/deployer wallet.

Parameters

Name Type Description
tokenId uint256 TokenId of the NFT to be burned.

retract

function retract(uint256 tokenId) external

Admin wallet to retract a property (NFT) from a customer.

Use case is the admin wallet needs to force claim an NFT from a customer.

Parameters

Name Type Description
tokenId uint256 TokenId of the property that needs to be retrackted.

returnProperty

function returnProperty(uint256 tokenId) external

Homeowners or NFT holders to return a property to ML wallet.

This will fail if the caller is not the owner of the NFT.

Parameters

Name Type Description
tokenId uint256 TokenId of the NFT to be returned.

approve

function approve(address to, uint256 tokenId) public

Allow homeowners/NFT holders to approve a 3rd party account to perform transactions on their behalf.

_This works like setApprovalForAll. The owner is giving ownership wo their NFT. Use case of this is an ML customer who would like to give an access to anyone to use the home/property. Requirements in order to make sure this call will succeed:

  • The property should be fully paid.
  • Function caller should be the ml admin deployer wallet.
  • Receiver should be the Marketplace contract address._

Parameters

Name Type Description
to address Wallet address who will be granted with the above permission.
tokenId uint256 TokenId of the NFT.

_beforeTokenTransfer

function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal

Transfer hooks. The functions inside will be executed as soon as the concerned NFT is being trasnferred.

_Operations inside this hook will be accomplished if either of the checks below were accomplished:

  • Customers cannot be able to transfer their NFTs if they are not yet fully paid.
  • Sender is the contract owner.
  • Receiver is the contract owner.
  • Caller of thid function is the Marketplace contract address._

Parameters

Name Type Description
from address Sender of the NFT.
to address Receiver of the NFT.
tokenId uint256 TokenId of the NFT.

_burn

function _burn(uint256 tokenId) internal

tokenURI

function tokenURI(uint256 tokenId) public view returns (string)

Query the tokenURI of an NFT.

Parameters

Name Type Description
tokenId uint256 TokenId of an NFT to be queried.

Return Values

Name Type Description
[0] string string - API address of the NFT's metadata

updateLifeTokenIssuanceRate

function updateLifeTokenIssuanceRate(uint256 tokenId, uint256 newLifeTokenIssuanceRate) external

updatePropertyCustodian

function updatePropertyCustodian(address _newPropertyCustodian) external

Update the property custodian.

New address set here will be the new owner of all returned NFTs/properties. Will emit PropertyCustodianUpdated event.

Parameters

Name Type Description
_newPropertyCustodian address Wallet address of the new property custodian.

Marketplace

Marketplace contract for ManageLife. This contract the market trading of NFTs in the ML ecosystem. In real life, an NFT here represents a home or real-estate property run by ManageLife.

mlAdmin

address mlAdmin

constructor

constructor() public

Deployer address will be considered as the ML admins

PERCENTS_DIVIDER

uint256 PERCENTS_DIVIDER

Percent divider to calculate ML's transaction earnings.

allowTrading

bool allowTrading

Trading status. This determines if normal users will be allowed to permitted to perform market trading (Bidding, Selling, Buy). By default Admin wallet will perform all these functions on behalf of all customers due to legal requirements. Once legal landscape permits, customers will be able to perform market trading by themselves.

mLife

contract ManageLife mLife

instance of the MLIFE NFT contract.

Offer

struct Offer {
  uint32 tokenId;
  address seller;
  uint256 price;
  address offeredTo;
}

Bid

struct Bid {
  address bidder;
  uint256 value;
}

adminPercent

uint256 adminPercent

Default admin fee.

adminPending

uint256 adminPending

Status for adming pending claimable earnings.

offers

mapping(uint256 => struct Marketplace.Offer) offers

Mapping of MLIFE tokenIds to Offers

bids

mapping(uint256 => struct Marketplace.Bid) bids

Mapping of MLIFE tokenIds to Bids

Offered

event Offered(uint256 tokenId, uint256 price, address toAddress)

BidEntered

event BidEntered(uint32 tokenId, uint256 value, address fromAddress)

BidCancelled

event BidCancelled(uint256 tokenId, uint256 value, address bidder)

Bought

event Bought(uint256 tokenId, uint256 value, address fromAddress, address toAddress, bool isInstant)

BidWithdrawn

event BidWithdrawn(uint256 tokenId, uint256 value)

Cancelled

event Cancelled(uint256 tokenId)

TradingStatus

event TradingStatus(bool _isTradingAllowed)

Received

event Received(address, uint256)

InvalidPercent

error InvalidPercent(uint256 _percent, uint256 minimumPercent)

pause

function pause() external

Security feature to Pause smart contracts transactions

unpause

function unpause() external

Unpausing the Paused transactions feature.

setTrading

function setTrading(bool _isTradingAllowed) external

Update the allowTrading status to true/false.

Can only be executed by contract owner. Will emit TradingStatus event.

Parameters

Name Type Description
_isTradingAllowed bool New boolean status to set.

setNftContract

function setNftContract(address nftAddress) external

Set the MLIFE contract.

Important to set this after deployment. Only MLIFE address is needed. Will not access 0x0 (zero/invalid) address.

Parameters

Name Type Description
nftAddress address Address of MLIFE contract.

setAdminPercent

function setAdminPercent(uint256 _percent) external

Allows admin wallet to set new percentage fee.

This throws an error is the new percentage is less than 500.

Parameters

Name Type Description
_percent uint256 New admin percentage.

withdraw

function withdraw() external

Withdraw marketplace earnings.

Can only be triggered by the admin wallet or contract owner. This will transfer the market earning to the admin wallet.

cancelForSale

function cancelForSale(uint32 tokenId) external

Cancel and existing sale offer.

Once triggered, the offer struct for this tokenId will be destroyed. Can only be called by MLIFE holders. The caller of this function should be the owner if the NFT in MLIFE contract.

Parameters

Name Type Description
tokenId uint32 TokenId of the NFT.

offerForSale

function offerForSale(uint32 tokenId, uint256 minSalePrice) external

Offer a property or NFT for sale in the marketplace.

If allowTrading is equals to true, users are allowed to execute this function. Else, admin wallet will facilitate the offering sale on their behalf.

Parameters

Name Type Description
tokenId uint32 MLIFE tokenId to be put on sale.
minSalePrice uint256 Minimum sale price of the property.

offerForSaleToAddress

function offerForSaleToAddress(uint32 tokenId, uint256 minSalePrice, address toAddress) external

Offer a property for sale to a specific wallet address only.

Allows MLIFE holders to sell their property to a specific wallet address. By default, this process is being performed by the admin wallet on behalf of the customers not until the allowTrading has been set to true.

Parameters

Name Type Description
tokenId uint32 TokenId of the property to be offered.
minSalePrice uint256 Minimum sale prices of the property.
toAddress address Wallet address on where the property will be offered to.

buy

function buy(uint32 tokenId) external payable

Allows users to buy a property that is registered in ML.

By default, this operation is disabled for customers. Only admin wallet can perform this on their behalf until the allowTrading variable is equals to true.

Parameters

Name Type Description
tokenId uint32 TokenId of the property.

placeBid

function placeBid(uint32 tokenId) external payable

Allows users to submit a bid to any properties.

By default, bidding is disabled for customers. Only admin wallet can perform bidding on their behalf until the allowTrading variable is equals to true.

Parameters

Name Type Description
tokenId uint32 tokenId of the property.

acceptBid

function acceptBid(uint32 tokenId, uint256 minPrice) external

Allows home owners to accept bids on their properties

Parameters

Name Type Description
tokenId uint32 tokenId of the property.
minPrice uint256 Minimum bidding price.

withdrawBid

function withdrawBid(uint32 tokenId) external

Allows bidders to withdraw their bid on a specific property.

There will be different process flows on this function depending on the value of allowTrading. By default, the entire trading will be facilitated by the admin wallet.

Parameters

Name Type Description
tokenId uint32 tokenId of the property that is currently being bid.

receive

receive() external payable

This records the address and ether value that was sent to the Marketplace

_safeTransferETH

function _safeTransferETH(address to, uint256 value) internal

Eth transfer hook

setMLAdmin

function setMLAdmin(address newAdminAddress) external

Allow admins to set new ML Admin wallet. Only contract owner/deployer can execute this function

Parameters

Name Type Description
newAdminAddress address New wallet address to be used.

onlyMLifeOwner

modifier onlyMLifeOwner()

Modifier to make sure only MLIFE NFT holders can run a specific functions.

isTradingAllowed

modifier isTradingAllowed()

Modifier to make sure only admin wallet can perform market tradings on behalf of all users.

allowTrading should be set to true in order for the users to facilitate the market trading by themselves.