Developers Guide

Core Features

The Orbit Protocol consists of two core components. In this example, we will be using ethers.js to interact with the Blast network.

  1. Space Station - The central hub for interacting with all assets and manages data such as account liquidity and health.

  2. OToken - Every asset has its own OToken contract that allows users to lend and borrow its underlying asset.

OToken

Core lending functions contained in each OToken. An OToken is a market for an underlying asset, such as Ether.

  • mint - Deposit funds (i.e. lend money) into the lending protocol and receive APY

  • redeem - Withdraw funds from the lending protocol

  • borrow - Borrow funds. The user must have deposited funds for any other asset and entered the market.

  • repayBorrow - Repay borrowed funds

Example

In this example, a user deposits ETH and borrows USDB against their collateral.

Notice: By default, any assets you lend will not automatically be used as collateral. You must enter a market in order to borrow against your assets.

import { ethers } from 'ethers';

const main = async () => {
    // Initialize provider, signer, and contract addresses
    const provider = new ethers.JsonRpcProvider(""); // Initialize with Blast Node
    const signer = new ethers.BaseWallet(new SigningKey("0x0"), ethers.provider); // Use your private keys
    
    // Contract addresses (found on the "Deployed Contracts" page)
    const spaceStationAddress = "";
    const oEtherAddress = "";
    const oUSDBAddress = "";
    
    // Setup contracts
    const spaceStationContract = new ethers.Contract(spaceStationAddress, SpaceStationABI, signer);
    const oEtherContract = new ethers.Contract(oEtherAddress, OTokenABI, signer);
    const oUSDBContract = new ethers.Contract(oUSDBAddress, OTokenABI, signer);
    const usdbUnderlying = await oUSDBContract.underlying();
    const USDBContract = new ethers.Contract(usdbUnderlying, OTokenABI, signer);
    
    // Lending operation (1 ETH) - Deposit funds and accrue APY
    const lendTx = await oEtherContract.mint({ value: BigInt(1 * 1e18) });
    await lendTx.wait();
    
    // Enabling ETH as collateral
    const enableCollateralTx = await spaceStationContract.enterMarkets([oEtherAddress]);
    await enableCollateralTx.wait();
    
    // Borrowing operation (1 USDB)
    const borrowTx = await oUSDBContract.borrow(BigInt(1 * 1e18));
    await borrowTx.wait();
    
    // Repayment process (including accrued interest)
    const owedAmount = (await oUSDBContract.getAccountSnapshot(signer.address))[2]; // Retrieve owed amount
    const approveTx = await USDBContract.approve(oUSDBAddress, owedAmount); // Approve the owed amount for transfer
    await approveTx.wait();
    const repayTx = await oUSDBContract.repayBorrow(owedAmount); // Repay the owed amount
    await repayTx.wait();
    
    // Withdraw collateral (ETH)
    const withdrawTx = await oEtherContract.redeemUnderlying(BigInt(1 * 1e18));
    await withdrawTx.wait();
}

main();

Lending

To lend and accrue APY, call the mint function in the contract of the desired token.

OEther (Ether)

To deposit funds into the contract, call mint with an Ether value alongside the transaction.

const lendTx = await oEtherContract.mint({ value: BigInt(1 * 1e18) });
await lendTx.wait();

OTokens (USDB, and others)

To deposit tokens, make sure to approve the tokens first. Then call mint with the amount as the first parameter.

// Approve
const approveTx = await USDBContract.approve(oUSDBAddress, amount);
await approveTx.wait();
// Lend tokens on Orbit
const lendTx = await oUSDBContract.mint(amount);
await lendTx.wait();

Entering Markets

If you wish to use your deposited funds as collateral, you must first call enterMarket in the Orbit Space Station contract.

// Enabling ETH as collateral
const enableCollateralTx = await spaceStationContract.enterMarkets([oEtherAddress]);
await enableCollateralTx.wait();

Last updated