Skip to main content

Check position

This tutorial will show you how to get data about deposits, borrows, and other position data.

Everything you need in one file

The tutorial source code is ready to be executed as a Foundry test in this file. The file contains all use cases and all comments from this page. Refer to the file for a forking setup and smart contract interfaces.

Code interacts with the wstETH / WETH silo market. SILO0 is the wstETH ERC4626 vault, SILO1 is the WETH ERC4626 vault. Silo protocol is permissionless, anyone can deploy the market for the same pair of assets using different market setup.

Get borrowable deposit amount

Get an amount of user's deposited assets. ERC4626 shares represent borrowable deposits that earn interest.

Get borrowable deposit amount
uint256 userShares = SILO1.balanceOf(EXAMPLE_USER);
uint256 userAssets = SILO1.previewRedeem(userShares);
assertEq(userAssets, 2 * 10**16, "User has 0.02 WETH deposited in the lending market");

Get deposit APR

10**18 current interest rate is equal to 100%/year.

Get deposit APR
uint256 currentDepositInterestRate = SILO_LENS.getDepositAPR(SILO0);
assertEq(currentDepositInterestRate, 119948832360394647, "Current deposit interest rate is ~11.99% / year");

Get protected deposit amount

When liquidity is fully borrowed out, deposits cannot be withdrawn. However, when the deposit is made as Protected (non-borrowable), which doesn't earn interest, the depositor can remove it at any time.

Get protected deposit amount
(address protectedShareToken,,) = SILO_CONFIG.getShareTokens(address(SILO1));
uint256 userProtectedShares = IShareToken(protectedShareToken).balanceOf(EXAMPLE_USER);
uint256 userProtectedAssets = SILO1.previewRedeem(userProtectedShares, ISilo.CollateralType.Protected);
assertEq(userProtectedAssets, 12345 * 10**11, "User has 0.0012345 WETH protected deposit");

Get full deposit amount (borrowable deposits + protected deposits)

Use SiloLens contracts can to get the total of borrowable + protected deposits per user.

Get full deposit amount
uint256 userRegularAndProtectedAssets = SILO_LENS.collateralBalanceOfUnderlying(SILO1, EXAMPLE_USER);

assertEq(
userRegularAndProtectedAssets,
212345 * 10**11,
"User has ~0.0212345 WETH in regular and protected deposits"
);

Get borrowed amount

Here is an example of a user supplying ETH collateral in silo1 and borrowing wstETH in silo0. Interest continually accrues to the growing user's debt. In the example, we calculate the user's borrowed amount as the repayable amount.

Get borrowed amount
uint256 userBorrowedAmount = SILO_LENS.debtBalanceOfUnderlying(SILO0, EXAMPLE_USER);
assertEq(userBorrowedAmount, 10402425735829051, "User have to repay ~0.0104 wstETH including interest");
assertEq(userBorrowedAmount, SILO0.maxRepay(EXAMPLE_USER), "Same way to read the debt amount");

Get borrow APR

10**18 current interest rate is equal to 100%/year.

Get borrow APR
uint256 currentBorrowInterestRate = SILO_LENS.getBorrowAPR(SILO0);
assertEq(currentBorrowInterestRate, 141827957285328000, "Current debt interest rate is ~14.18% / year");

Get Loan-to-Value ratio (LTV)

0.5 * 10**18 LTV is for a position with 10collateraland5 collateral and 5 borrowed assets.

Get Loan-to-Value ratio
uint256 userLTVSilo0 = SILO_LENS.getLtv(SILO0, EXAMPLE_USER);
uint256 userLTVSilo1 = SILO_LENS.getLtv(SILO1, EXAMPLE_USER);
assertEq(userLTVSilo0, 579636700972035697, "User loan-to-value ratio is ~58%");
assertEq(userLTVSilo0, userLTVSilo1, "User loan-to-value ratio is consistent for both silos in SiloConfig");

Get solvency

Check if the user is solvent. Borrow positions can be liquidated for insolvent positions.

Get solvency
bool isSolventSilo0 = SILO0.isSolvent(EXAMPLE_USER);
bool isSolventSilo1 = SILO1.isSolvent(EXAMPLE_USER);
assertTrue(isSolventSilo0, "User is solvent");
assertEq(isSolventSilo0, isSolventSilo1, "Solvency is consistent for both silos in SiloConfig");