IAssetManager

Git Source

Author: bull.haus

Registers all assets supported for P2P loans on Lumin.

Functions

pause

Pause contract.

function pause() external;

unpause

Unpause contract.

function unpause() external;

addAsset

Add asset to the platform. This allows users to deposit, withdraw and lend with this asset.

Only ERC20 assets are currently supported.

function addAsset(AssetType assetType, address assetAddress, string calldata symbol, uint256 collectionId) external;

Parameters

NameTypeDescription
assetTypeAssetTypetype of added asset
assetAddressaddresscontract address of added asset
symbolstringasset symbol (e.g. BTC, ETH)
collectionIduint256id of asset collection. This does not apply to ERC20 assets, and is set to 0 by default

updateAssetEnabledStatus

Enable / disable asset.

Assets configs can not be deleted; disable assets when not supported anymore.

function updateAssetEnabledStatus(uint256 assetId, bool enabled) external;

Parameters

NameTypeDescription
assetIduint256unique asset identifier
enabledbooltrue to enable asset, false to disable asset

assetDepositWithdraw

Deposit or withdraw asset from user's account

Only AssetActionType.Deposit and AssetActionType.Withdraw are allowed

function assetDepositWithdraw(uint256 assetId, AssetActionType action, uint256 amount) external;

Parameters

NameTypeDescription
assetIduint256asset id to deposit or withdraw
actionAssetActionTypeasset action to perform (AssetActionType.Deposit, AssetActionType.Withdraw)
amountuint256amount to deposit or withdraw

assetTransferOnLoanAction

Transfer assets from one user to another.

Transfers happen for payments (e.g. interest), lending (transferring lent money) and seizing (liquidated loan). Transfers are performed on user's deposits on Lumin, no ERC20 transfers are executed.

function assetTransferOnLoanAction(
    uint256 assetId,
    AssetActionType action,
    address userAddressFrom,
    address userAddressTo,
    uint256 amount
) external;

Parameters

NameTypeDescription
assetIduint256asset id to transfer
actionAssetActionTypeaction to perform
userAddressFromaddressaddress to transfer asset from
userAddressToaddressaddress to transfer asset to
amountuint256to transfer

assetLockUnlock

Lock / unlock asset.

This method is called by the LoanManager

function assetLockUnlock(uint256 assetId, AssetActionType action, address userAddress, uint256 amount) external;

Parameters

NameTypeDescription
assetIduint256asset id to (un)lock
actionAssetActionTypelock / unlock
userAddressaddressuser address to (un)lock for
amountuint256amount to (un)lock

setPriceFeedProxy

Set price feed proxy address

function setPriceFeedProxy(uint256 index, address priceFeedProxyAddress) external;

Parameters

NameTypeDescription
indexuint256index to store price feed proxy at
priceFeedProxyAddressaddressaddress of price feed proxy. Setting address(0) reverts with ZeroAddress.

updatePriceFeedProxyEnableStatus

Enable / disable price feed proxy by address

Price feed proxy has to be added with addPriceFeedProxy first.

function updatePriceFeedProxyEnableStatus(uint256 index, bool enabled) external;

Parameters

NameTypeDescription
indexuint256price feed proxy index
enabledbooltrue to enable, false to disable price feed proxy

setAssetPriceFeed

Set price feed for asset at given index

function setAssetPriceFeed(uint256 assetId, uint256 priceFeedIndex, address priceFeedAddress) external;

Parameters

NameTypeDescription
assetIduint256asset id to set price feed for
priceFeedIndexuint256index of price feed to set
priceFeedAddressaddressaddress of price feed. Setting address(0) reverts with ZeroAddress.

updateAssetPriceFeedEnableStatus

Enable / disable price feed for asset at given index

function updateAssetPriceFeedEnableStatus(uint256 assetId, uint256 priceFeedIndex, bool enabled) external;

Parameters

NameTypeDescription
assetIduint256asset id to enable/disable price feed for
priceFeedIndexuint256index of price feed to set
enabledbooltrue to enable, false to disable

getRegisteredAssetIDs

Retrieve all known asset IDs

When asset IDs are unknown, this method can be used to find all known assets. Since the data is read from an EnumerableSet, the asset ID belonging to a certain index may change. This does not matter, as it is the asset ID that is important, not its index.

Assets can be enabled and disabled but never deleted. A returned known asset ID does not imply that this asset is currently enabled.

function getRegisteredAssetIDs() external view returns (uint256[] memory);

Returns

NameTypeDescription
<none>uint256[]list of all known asset IDs

depositOf

Get deposit of asset assetId for user userAddress.

Returns 0 deposit for non-existent assets or users.

function depositOf(uint256 assetId, address userAddress) external view returns (DepositData memory userDeposit);

Parameters

NameTypeDescription
assetIduint256id of asset
userAddressaddressuser's address to get deposit for

Returns

NameTypeDescription
userDepositDepositDataDeposit of userAddress for asset assetAddress

balancesOf

Get deposits and balances for user userAddress.

This method is used to quickly retrieve the most important dashboard data by the front-end, with one RPC call.

function balancesOf(address userAddress)
    external
    view
    returns (
        uint256[] memory assetIds,
        DepositData[] memory depositsTotal,
        DepositData[] memory depositsUser,
        uint256[] memory balances
    );

Parameters

NameTypeDescription
userAddressaddressuser's address to get balances for. address(0) for asset totals.

Returns

NameTypeDescription
assetIdsuint256[]Ordered list of asset ids for which balances are returned
depositsTotalDepositData[]Ordered list of total Deposits
depositsUserDepositData[]Ordered list of Deposits of userAddress
balancesuint256[]Ordered list of wallet balances of userAddress. Empty array if userAddress is address(0).

getPriceFeedProxies

Get all price feed proxies

function getPriceFeedProxies() external view returns (EnabledAddress[MAX_PRICE_FEED_PROXIES] memory);

Returns

NameTypeDescription
<none>EnabledAddress[MAX_PRICE_FEED_PROXIES]Array of all price feed proxies

getPriceFeedProxyAddress

Get price feed proxy address by index

function getPriceFeedProxyAddress(uint256 index) external view returns (address);

Parameters

NameTypeDescription
indexuint256index to get price feed proxy address from

Returns

NameTypeDescription
<none>addressaddress of price feed proxy at index

getAsset

Retrieve asset information based on its asset ID

function getAsset(uint256 assetId)
    external
    view
    returns (Asset memory asset, EnabledAddress[MAX_PRICE_FEED_PROXIES] memory priceFeeds);

Parameters

NameTypeDescription
assetIduint256asset ID to find information for

Returns

NameTypeDescription
assetAssetasset details
priceFeedsEnabledAddress[MAX_PRICE_FEED_PROXIES]configured price feeds for asset

Events

AssetAction

Emitted when an asset is transferred or (un)locked on the platform.

event AssetAction(uint256 indexed assetId, AssetActionType indexed action, address indexed userAddress, uint256 amount);

AssetAdded

Emitted when asset is been added.

event AssetAdded(
    uint256 indexed assetId, address indexed assetAddress, uint256 indexed collectionId, AssetType assetType
);

AssetEnabledStatusUpdated

Indicates that an asset has been enabled / disabled.

Only assets that have been added to the platform can be enabled.

event AssetEnabledStatusUpdated(uint256 indexed assetId, bool indexed enabled);

PriceFeedEnabledStatusUpdated

Emitted when a price feed status has been updated

event PriceFeedEnabledStatusUpdated(uint256 assetId, uint256 priceFeedIndex, bool enabled);

PriceFeedSet

Emitted when a price feed has been set for an asset

event PriceFeedSet(uint256 assetId, uint256 priceFeedIndex, address priceFeedAddress);

PriceFeedProxySet

Emitted when a price feed proxy has been added

event PriceFeedProxySet(address indexed priceFeedProxyAddress, uint256 indexed index);

PriceFeedProxyEnabledStatus

Emitted when a price feed proxy status has been updated

event PriceFeedProxyEnabledStatus(uint256 indexed index, bool indexed enabled);

Errors

AssetAlreadyRegistered

Registering already existing assets revert with AssetAlreadyRegistered.

error AssetAlreadyRegistered();

AssetNotEnabled

Using assets currently not enabled revert with AssetNotEnabled,

error AssetNotEnabled();

AssetNotFound

Getting non-existent assets reverts with AssetNotFound,

error AssetNotFound();

InsufficientFunds

Transferring more assets than currently in free deposits reverts with InsufficientFunds.

Transfers are deposits, payments, taking loans, ..

error InsufficientFunds();

InvalidAction

Performing an asset action not supported by the called method revert with InvalidAction.

error InvalidAction();

PriceFeedAlreadySet

Overwriting a previously set price feed reverts with PriceFeedAlreadySet

Changing the contract could result in unwanted issues like liquidations.

error PriceFeedAlreadySet();

PriceFeedNotSet

Actions on price feed proxies that were not configured, revert with PriceFeedNotSet.

error PriceFeedNotSet();

PriceFeedProxyDisabled

Actions on disabled price feed proxies, revert with ProxyDisabled

error PriceFeedProxyDisabled();

PriceFeedProxyAlreadySet

Overwriting a previously set price feed proxy reverts with PriceFeedProxyAlreadySet.

Changing the contract could result in unwanted issues like liquidations.

Disable the price feed proxy instead, and add a new one on a different index.

error PriceFeedProxyAlreadySet();

ZeroAddress

Setting a price feed or proxy with zero address reverts with ZeroAddress.

error ZeroAddress();

ZeroAmount

Performing asset actions on "0" amount of tokens reverts with ZeroAmount.

error ZeroAmount();

Structs

DepositData

Tuple containing amount deposited, and total amount locked over all loans.

(Un)locking assets does not change the deposit amount; 0 <= locked <= amount at all times.

depositAmount Total amount of asset deposited into user's account.

lockedAmount Amount of depositAmount that is currently locked as collateral.

struct DepositData {
    uint256 depositAmount;
    uint256 lockedAmount;
}

Asset

Asset configuration.

Assets shall not be deleted to prevent invalid loans, they should be enabled/disabled instead.

assetType Type of asset (e.g. ERC20).

collectionId Collection ID, only used for ERC1155 assets.

data Asset contract address and enabled status. Disabled assets cannot be used in new loans or for deposits.

struct Asset {
    AssetType assetType;
    uint256 collectionId;
    EnabledAddress data;
}

EnabledAddress

Tuple of address and enabled flag

Used by different types

enabled true when the current asset or contract can be used, false otherwise.

addr asset or contract address.

struct EnabledAddress {
    bool enabled;
    address addr;
}

Enums

AssetActionType

Asset action to perform.

The respective values are used for performing asset action methods and emitted events.

NotSupported 0-value used to indicate an invalid action.

Lock Lock user's deposit.

Unlock Unlock user's deposit.

Deposit Deposit asset to user's unlocked deposit.

Withdraw Withdraw asset from user's unlocked deposit.

Lend Lend an asset from lender to borrower.

PayFees Pay platform fees for newly created loan from borrower's deposit.

PayInterest Pay loan interest to lenders.

PayPrincipal Pay principal to lenders.

Seize Seize collateral from borrower on liquidation.

enum AssetActionType {
    NotSupported,
    Lock,
    Unlock,
    Deposit,
    Withdraw,
    Lend,
    PayFees,
    PayInterest,
    PayPrincipal,
    Seize
}

AssetType

Type of asset indicates where to read and how to handle user deposits and collateral.

Disabled has value 0 so that by default all non-configured assets are marked as disabled. ERC1155Fungible are assets within an ERC1155 contract, where amount > 1, and are thus fungible. ERC1155NonFungible are assets within an ERC1155 contract, where amount == 1, and are thus non-fungible.

enum AssetType {
    Disabled,
    ERC20
}