Supply & Withdraw

Supply

supply

function supply(
    address asset,
    uint256 amount,
    address onBehalfOf,
    uint16 referralCode
) external

Supplies a certain amount of an underlying asset into the Helios protocol, in exchange for minting an equivalent amount of hTokens (Helios interest-bearing tokens) to the supplier.

  • The caller must approve the Helios Pool contract to spend at least amount of the asset beforehand (via the standard ERC-20 approve() call, unless using the permit variant). When supply() is executed, the Pool transfers the specified amount of the underlying asset from the sender to the protocol, and mints the corresponding hTokens to the onBehalfOf address.

  • If onBehalfOf is the same as the sender (msg.sender), the user will receive the hTokens in their own wallet (typical case). If onBehalfOf is a different address, it allows supplying on behalf of another user (the hTokens will be owned by that other address, which will then have the right to withdraw the asset later).

  • Interest accrual: Once supplied, the underlying asset earns interest over time. The accrued interest is reflected by the increasing exchange rate between hTokens and the underlying asset. (hTokens continuously appreciate in value relative to the underlying.)

  • Referral code: The referralCode is an optional parameter for integrating referral rewards. This code is recorded in the supply event for potential future reward distribution. In the current Helios version, the referral system is inactive – it’s safe to pass 0 for this value. (If Helios activates a referral program via governance, integrators could use this code to track referrals.)

Example: If a user supplies 100 USDT to the pool (and uses their own address as onBehalfOf), they will receive 100 hUSDT in return. Those 100 hUSDT represent their deposit plus accruing interest; the user can use the hUSDT balance to withdraw the underlying USDT later.

Supply with Permit: Helios may also support a permit-version of supply (e.g. supplyWithPermit) which allows combining the approve and supply into a single transaction using an EIP-2612 permit signature. This functions similarly to supply but accepts permitV, permitR, permitS parameters along with a deadline, saving an extra transaction for approval.

Withdraw

withdraw

function withdraw(
    address asset,
    uint256 amount,
    address to
) external returns (uint256)

Withdraws an amount of the underlying asset from the protocol, by burning the equivalent hTokens from the user’s balance. This returns the underlying asset to the user (or to a specified address).

  • When a user calls withdraw, the Pool burns the specified amount of hTokens from the caller (reducing their interest-bearing balance) and transfers the corresponding amount of the underlying asset to the to address. For example, if a user has 100 hUSDC and withdraws 100 USDC, their 100 hUSDC are burned and 100 USDC is sent back to them.

  • If the user’s account has outstanding borrows, the protocol will only allow withdrawing an amount such that the user’s health factor (HF) remains >= 1. In other words, a user cannot withdraw so much that their remaining collateral cannot support their current loans. The maximum withdrawable amount is constrained by the collateralization requirements. If a user attempts to withdraw more than is safely allowed, the transaction will revert for violating collateral constraints.

  • The amount parameter is expressed in the underlying asset’s smallest units (wei, if 18 decimals). To withdraw the entire deposit of that asset, the user can pass type(uint256).max as the amount. In that case, Helios will calculate the full withdrawable balance of the user’s hTokens and withdraw all of it.

  • If withdrawing to a different address (to is not the caller), the caller must be the owner of the hTokens being burned. Essentially, one could call withdraw to send the underlying to another address (useful if, for example, withdrawing to a cold wallet), but you cannot withdraw someone else’s deposits unless you hold their hTokens.

  • Collateral usage note: If an asset has a Loan-To-Value (LTV) of 0% (meaning it cannot be used as collateral at all), it must be either fully withdrawn or explicitly disabled as collateral (via setUserUseReserveAsCollateral) before the user can withdraw other assets or borrow against other collateral. In practice, if you have supplied an asset with 0% LTV and marked it as collateral, you won’t be able to borrow or withdraw other collateralized assets until you remove that 0% LTV asset from collateral (because it doesn’t contribute to your borrowing power). Always ensure that assets with 0% LTV are not enabled as collateral if you intend to utilize your other supplied assets for borrowing.

Return value: On success, withdraw returns the actual amount of the underlying asset that was withdrawn (as a uint256). In most cases this equals the requested amount, but if type(uint256).max was used, the return value indicates the total balance withdrawn.

Last updated